typeorm#Table TypeScript Examples
The following examples show how to use
typeorm#Table.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: 1586803516725-CreateUsers.ts From gobarber-api with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'users',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'name',
type: 'varchar',
},
{
name: 'email',
type: 'varchar',
isUnique: true,
},
{
name: 'password',
type: 'varchar',
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
}),
);
}
Example #2
Source File: 1602355203224-create_images.ts From happy with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(new Table({
name: 'images',
columns: [
{
name: 'id',
type: 'integer',
unsigned: true,
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'path',
type: 'varchar',
},
{
name: 'orphanage_id',
type: 'integer',
},
],
foreignKeys: [
{
name: 'ImageOrphanage',
columnNames: ['orphanage_id'],
referencedTableName: 'orphanages',
referencedColumnNames: ['id'],
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
}
],
}))
}
Example #3
Source File: 1586825793555-CreateCategories.ts From rocketseat-gostack-11-desafios with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'categories',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'title',
type: 'varchar',
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
}),
);
}
Example #4
Source File: 1589508329414-Appointment.ts From hotseat-api with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'appointments',
columns: [
{
name: 'id',
type: 'varchar',
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
isPrimary: true,
},
{
name: 'provider',
type: 'varchar',
isNullable: false,
},
{
name: 'date',
type: 'timestamp with time zone',
isNullable: false,
},
],
}),
);
}
Example #5
Source File: 1563594307396-Initial.ts From barista with Apache License 2.0 | 6 votes |
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.createTable(new Table({ name: 'bill_of_material' }));
await queryRunner.createTable(new Table({ name: 'license' }));
await queryRunner.createTable(new Table({ name: 'license_scan_result' }));
await queryRunner.createTable(new Table({ name: 'license_scan_result_item' }));
await queryRunner.createTable(new Table({ name: 'obligation' }));
await queryRunner.createTable(new Table({ name: 'project' }));
await queryRunner.createTable(new Table({ name: 'scan' }));
await queryRunner.createTable(new Table({ name: 'security_scan_result' }));
}
Example #6
Source File: 2_MigrationLog.ts From ADR-Gateway with MIT License | 6 votes |
Perform = async (db: Connection) => {
await db.createQueryRunner().createTable(new Table({
name: `${db.options.entityPrefix || ""}MigrationLog`,
columns: [{
name: "id",
type: "varchar",
length: "255"
},{
name: "performed",
type: "varchar",
length: "40"
}]
}))
}
Example #7
Source File: 1591136705006-CreateItems.ts From ecoleta with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'items',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'image',
type: 'varchar',
},
{
name: 'title',
type: 'varchar',
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
}),
);
}
Example #8
Source File: 1602644208420-CreateImages.ts From NextLevelWeek with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(new Table({
name: 'images',
columns: [
{
name: 'id',
type: 'uuid',
unsigned: true,
isPrimary: true,
isGenerated: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'path',
type: 'varchar',
},
{
name: 'orphanage_id',
type: 'integer',
}
],
foreignKeys: [
{
name: 'ImageOrphanage',
columnNames: ['orphanage_id'],
referencedTableName: 'orphanages',
referencedColumnNames: ['id'],
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
}
]
}));
}
Example #9
Source File: 1605809764812-CreateAppointments.ts From gobarber-project with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'appointments',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'provider',
type: 'varchar',
},
{
name: 'date',
type: 'timestamp without time zone',
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
}),
);
}
Example #10
Source File: 1586952790781-CreateAppointments.ts From GoBarber with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'appointments',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'provider',
type: 'varchar',
isNullable: false,
},
{
name: 'date',
type: 'timestamp with time zone',
isNullable: false,
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
}),
);
}
Example #11
Source File: withTimestamp.test.ts From backend-postgres-typescript-node-express with MIT License | 6 votes |
describe('withTimestampsMigration', () => {
it('should generate a TypeORM table with timestamps', () => {
const table = new Table(
withTimestampsMigration({
columns: [
{
generationStrategy: 'uuid',
isGenerated: true,
isPrimary: true,
name: 'id',
type: 'uuid',
},
{
isNullable: false,
name: 'email',
type: 'varchar',
},
],
name: 'users',
}),
)
expect(table.columns).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'created_at' })]))
expect(table.columns).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'updated_at' })]))
expect(table.columns).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'deleted_at' })]))
})
})
Example #12
Source File: 1602691088861-create_images.ts From happy with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(new Table({
name: "images",
columns: [
{
name: "id",
type: "integer",
unsigned: true,
isPrimary: true,
isGenerated: true,
generationStrategy: "increment"
},
{
name: "path",
type: "varchar"
},
{
name: "orphanage_id",
type: "integer"
}
],
foreignKeys: [
{
name: "ImageOrphanage",
columnNames: ["orphanage_id"],
referencedTableName: "orphanages",
referencedColumnNames: ["id"],
onUpdate: "CASCADE",
onDelete: "CASCADE"
}
]
}));
}
Example #13
Source File: 1580233549383-CreateRole.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
public async up(queryRunner: QueryRunner): Promise<any> {
const table = new Table({
name: 'role',
columns: [
{
name: 'uuid',
type: 'varchar',
length: '255',
isPrimary: true,
isUnique: true,
isNullable: false,
}, {
name: 'name',
type: 'varchar',
length: '255',
isPrimary: false,
isNullable: false,
}, {
name: 'updatedAt',
type: 'timestamp',
isPrimary: false,
isNullable: false,
}, {
name: 'createdAt',
type: 'timestamp',
isPrimary: false,
isNullable: false,
},
],
});
await queryRunner.createTable(table);
}
Example #14
Source File: 1601404945917-create_images.ts From nlw-03-omnistack with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(new Table({
name: 'images',
columns: [
{
name: 'id',
type: 'integer',
unsigned: true,
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'path',
type: 'varchar'
},
{
name: 'orphanage_id',
type: 'integer',
}
],
foreignKeys: [
{
name: 'ImageOrphanage',
columnNames: ['orphanage_id'],
referencedColumnNames: ['id'],
referencedTableName: 'orphanages',
onUpdate: 'CASCADE',
onDelete: 'CASCADE'
}
]
}))
}
Example #15
Source File: 1602629877063-create_orphanages.ts From NLW-3.0 with MIT License | 5 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(new Table({
name: 'orphanages',
columns: [
{
name: 'id',
type: 'integer',
unsigned: true,
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'name',
type: 'varchar'
},
{
name: 'latitude',
type: 'decimal',
scale: 10,
precision: 2,
},
{
name: 'longitude',
type: 'decimal',
scale: 10,
precision: 2,
},
{
name: 'about',
type: 'text',
},
{
name: 'instructions',
type: 'text',
},
{
name: 'opening_hours',
type: 'varchar',
},
{
name: 'open_on_weekends',
type: 'boolean',
default: false,
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
}
]
}))
}
Example #16
Source File: 1586807241835-CreateAppointments.ts From gobarber-api with MIT License | 5 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'appointments',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'provider_id',
type: 'uuid',
isNullable: true,
},
{
name: 'date',
type: 'timestamp with time zone',
},
{
name: 'created_at',
type: 'timestamp with time zone',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp with time zone',
default: 'now()',
},
],
}),
);
await queryRunner.createForeignKey(
'appointments',
new TableForeignKey({
columnNames: ['provider_id'],
referencedColumnNames: ['id'],
referencedTableName: 'users',
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
}),
);
}
Example #17
Source File: 1602353047187-create_orphanages.ts From happy with MIT License | 5 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(new Table({
name: 'orphanages',
columns: [
{
name: 'id',
type: 'integer',
unsigned: true,
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'name',
type: 'varchar',
},
{
name: 'latitude',
type: 'decimal',
scale: 10,
precision: 2,
},
{
name: 'longitude',
type: 'decimal',
scale: 10,
precision: 2,
},
{
name: 'about',
type: 'text',
},
{
name: 'instructions',
type: 'text',
},
{
name: 'opening_hours',
type: 'varchar',
},
{
name: 'open_on_weekends',
type: 'boolean',
default: false,
},
]
}))
}
Example #18
Source File: 1586825890642-CreateTransactions.ts From rocketseat-gostack-11-desafios with MIT License | 5 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'transactions',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'title',
type: 'varchar',
},
{
name: 'value',
type: 'float',
},
{
name: 'type',
type: 'varchar',
},
{
name: 'category_id',
type: 'uuid',
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
}),
);
await queryRunner.createForeignKey(
'transactions',
new TableForeignKey({
columnNames: ['category_id'],
referencedColumnNames: ['id'],
referencedTableName: 'categories',
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
}),
);
}
Example #19
Source File: 1591136957524-CreatePoints.ts From ecoleta with MIT License | 5 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'points',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'image',
type: 'varchar',
isNullable: true,
},
{
name: 'name',
type: 'varchar',
},
{
name: 'email',
type: 'varchar',
},
{
name: 'whatsapp',
type: 'varchar',
},
{
name: 'latitude',
type: 'float',
},
{
name: 'longitude',
type: 'float',
},
{
name: 'city',
type: 'varchar',
},
{
name: 'uf',
type: 'varchar',
length: '2',
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
}),
);
}
Example #20
Source File: 1602638825173-CreateOrphanages.ts From NextLevelWeek with MIT License | 5 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(new Table({
name: 'orphanages',
columns: [
{
name: 'id',
type: 'uuid',
unsigned: true,
isPrimary: true,
isGenerated: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'name',
type: 'varchar'
},
{
name: 'latitude',
type: 'decimal',
scale: 10,
precision: 2,
},
{
name: 'longitude',
type: 'decimal',
scale: 10,
precision: 2,
},
{
name: 'about',
type: 'text',
},
{
name: 'instructions',
type: 'text',
},
{
name: 'opening_hours',
type: 'varchar',
},
{
name: 'open_on_weekends',
type: 'boolean',
default: false
},
]
}));
}
Example #21
Source File: 1634308884591-Stickers.ts From fosscord-server with GNU Affero General Public License v3.0 | 5 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropForeignKey("read_states", "FK_6f255d873cfbfd7a93849b7ff74");
await queryRunner.changeColumn(
"stickers",
"tags",
new TableColumn({ name: "tags", type: "varchar", isNullable: true })
);
await queryRunner.changeColumn(
"stickers",
"pack_id",
new TableColumn({ name: "pack_id", type: "varchar", isNullable: true })
);
await queryRunner.changeColumn("stickers", "type", new TableColumn({ name: "type", type: "integer" }));
await queryRunner.changeColumn(
"stickers",
"format_type",
new TableColumn({ name: "format_type", type: "integer" })
);
await queryRunner.changeColumn(
"stickers",
"available",
new TableColumn({ name: "available", type: "boolean", isNullable: true })
);
await queryRunner.changeColumn(
"stickers",
"user_id",
new TableColumn({ name: "user_id", type: "boolean", isNullable: true })
);
await queryRunner.createForeignKey(
"stickers",
new TableForeignKey({
name: "FK_8f4ee73f2bb2325ff980502e158",
columnNames: ["user_id"],
referencedColumnNames: ["id"],
referencedTableName: "users",
onDelete: "CASCADE",
})
);
await queryRunner.createTable(
new Table({
name: "sticker_packs",
columns: [
new TableColumn({ name: "id", type: "varchar", isPrimary: true }),
new TableColumn({ name: "name", type: "varchar" }),
new TableColumn({ name: "description", type: "varchar", isNullable: true }),
new TableColumn({ name: "banner_asset_id", type: "varchar", isNullable: true }),
new TableColumn({ name: "cover_sticker_id", type: "varchar", isNullable: true }),
],
foreignKeys: [
new TableForeignKey({
columnNames: ["cover_sticker_id"],
referencedColumnNames: ["id"],
referencedTableName: "stickers",
}),
],
})
);
}
Example #22
Source File: 1597260275210-create-request-table.ts From opensaas with MIT License | 5 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
const columns = [
{
name: 'id',
type: 'serial',
isPrimary: true,
isUnique: true,
},
{
name: 'tenantId',
type: 'varchar',
length: '256',
isNullable: false,
},
{
name: 'url',
type: 'text',
isNullable: false,
},
{
name: 'statusCode',
type: 'smallint',
isNullable: false,
},
{
name: 'userAgent',
type: 'text',
isNullable: false,
},
{
name: 'ip',
type: 'varchar',
length: '32',
isNullable: false,
},
{
name: 'createdAt',
type: 'timestamp',
isNullable: false,
},
{
name: 'updatedAt',
type: 'timestamp',
isNullable: false,
},
];
const table = new Table({ columns, name: 'requests' });
await queryRunner.createTable(table, true);
}
Example #23
Source File: 1606945429024-CreateUserTokens.ts From gobarber-project with MIT License | 5 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'user_tokens',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'token',
type: 'uuid',
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'user_id',
type: 'uuid',
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
foreignKeys: [
{
name: 'TokenUser',
referencedTableName: 'users',
referencedColumnNames: ['id'],
columnNames: ['user_id'],
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
},
],
}),
);
}
Example #24
Source File: 1589741112746-CreateUserToken.ts From GoBarber with MIT License | 5 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'user_tokens',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'token',
type: 'uuid',
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'user_id',
type: 'uuid',
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
foreignKeys: [
{
name: 'TokenUser',
referencedTableName: 'users',
referencedColumnNames: ['id'],
columnNames: ['user_id'],
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
},
],
}),
);
}
Example #25
Source File: 1602681187435-create_orphanages.ts From happy with MIT License | 5 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable( new Table({
name: "orphanages",
columns: [
{
name: "id",
type: "integer",
unsigned: true,
isPrimary: true,
isGenerated: true,
generationStrategy: "increment"
},
{
name: "name",
type: "varchar"
},
{
name: "latitude",
type: "decimal",
scale: 10,
precision: 2
},
{
name: "longitude",
type: "decimal",
scale: 10,
precision: 2
},
{
name: "about",
type: "text"
},
{
name: "instructions",
type: "text"
},
{
name: "opening_hours",
type: "varchar"
},
{
name: "open_on_weekends",
type: "boolean",
default: false
}
]
}));
}
Example #26
Source File: 1577795598123-CreateUser.ts From radiopanel with GNU General Public License v3.0 | 5 votes |
public async up(queryRunner: QueryRunner): Promise<any> {
const table = new Table({
name: 'user',
columns: [
{
name: 'uuid',
type: 'varchar',
length: '255',
isPrimary: true,
isNullable: false,
}, {
name: 'username',
type: 'varchar',
length: '255',
isPrimary: false,
isNullable: false,
}, {
name: 'email',
type: 'varchar',
length: '255',
isPrimary: false,
isNullable: false,
}, {
name: 'password',
type: 'varchar',
length: '255',
isPrimary: false,
isNullable: false,
}, {
name: 'updatedAt',
type: 'timestamp',
isPrimary: false,
isNullable: false,
}, {
name: 'createdAt',
type: 'timestamp',
isPrimary: false,
isNullable: false,
},
],
});
await queryRunner.createTable(table);
}
Example #27
Source File: 1601399238009-create_orphanages.ts From nlw-03-omnistack with MIT License | 5 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(new Table({
name: 'orphanages',
columns: [
{
name: 'id',
type: 'integer',
unsigned: true,
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'name',
type: 'varchar',
},
{
name: 'latitude',
type: 'decimal',
scale: 10,
precision: 2,
},
{
name: 'longitude',
type: 'decimal',
scale: 10,
precision: 2,
},
{
name: 'about',
type: 'text',
},
{
name: 'instructions',
type: 'text',
},
{
name: 'open_on_weekends',
type: 'boolean',
default: false,
},
]
}))
}
Example #28
Source File: 1546516990326-CreateUserGroupTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
public async up(queryRunner: QueryRunner): Promise<any> {
const table = new Table({
name: 'user_group',
columns: [
{
name: 'group_id',
type: 'int',
length: '11',
isPrimary: true,
isNullable: false,
isGenerated: true,
generationStrategy: 'increment',
}, {
name: 'name',
type: 'varchar',
length: '64',
isPrimary: false,
isNullable: true,
}, {
name: 'slug',
type: 'varchar',
length: '64',
isPrimary: false,
isNullable: true,
}, {
name: 'is_active',
type: 'int',
length: '11',
isPrimary: false,
isNullable: true,
} , {
name: 'created_date',
type: 'datetime',
isPrimary: false,
isNullable: true,
default: 'CURRENT_TIMESTAMP',
} , {
name: 'modified_date',
type: 'datetime',
isPrimary: false,
isNullable: true,
default: 'CURRENT_TIMESTAMP',
} , {
name: 'created_by',
type: 'int',
length: '11',
isPrimary: false,
isNullable: true,
} , {
name: 'modified_by',
type: 'int',
length: '11',
isPrimary: false,
isNullable: true,
} ,
],
});
const ifExsist = await queryRunner.hasTable('user_group');
if (!ifExsist) {
await queryRunner.createTable(table);
}
}