typeorm#TableForeignKey TypeScript Examples
The following examples show how to use
typeorm#TableForeignKey.
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: 1588957767413-AddUserIdToAppointments.ts From gobarber-api with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.addColumn(
'appointments',
new TableColumn({
name: 'user_id',
type: 'uuid',
isNullable: true,
}),
);
await queryRunner.createForeignKey(
'appointments',
new TableForeignKey({
name: 'AppointmentUser',
columnNames: ['user_id'],
referencedTableName: 'users',
referencedColumnNames: ['id'],
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
}),
);
}
Example #2
Source File: 1589854644313-AddUserIdToAppointments.ts From GoBarber with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.addColumn(
'appointments',
new TableColumn({
name: 'user_id',
type: 'uuid',
isNullable: true,
}),
);
await queryRunner.createForeignKey(
'appointments',
new TableForeignKey({
name: 'AppointmentUser',
columnNames: ['user_id'],
referencedColumnNames: ['id'],
referencedTableName: 'users',
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
}),
);
// Cascade
}
Example #3
Source File: 1586960843260-AlterProviderFildToProviderId.ts From GoBarber with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropColumn('appointments', 'provider');
await queryRunner.addColumn(
'appointments',
new TableColumn({
name: 'provider_id',
type: 'uuid',
isNullable: true,
}),
);
await queryRunner.createForeignKey(
'appointments',
new TableForeignKey({
name: 'AppointmentProvider',
columnNames: ['provider_id'],
referencedColumnNames: ['id'],
referencedTableName: 'users',
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
}),
);
// Cascade
}
Example #4
Source File: 1607519094790-CreateUsersRoles.ts From gobarber-project with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'users_roles',
columns: [
{ name: 'role_id', type: 'uuid' },
{ name: 'user_id', type: 'uuid' },
],
}),
);
await queryRunner.createForeignKey(
'users_roles',
new TableForeignKey({
columnNames: ['role_id'],
referencedColumnNames: ['id'],
referencedTableName: 'roles',
name: 'fk_roles_user',
onDelete: 'CASCADE',
onUpdate: 'SET NULL',
}),
);
await queryRunner.createForeignKey(
'users_roles',
new TableForeignKey({
columnNames: ['user_id'],
referencedColumnNames: ['id'],
referencedTableName: 'users',
name: 'fk_users_roles',
onDelete: 'CASCADE',
onUpdate: 'SET NULL',
}),
);
}
Example #5
Source File: 1607519026726-CreatePermissionsRoles.ts From gobarber-project with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'permissions_roles',
columns: [
{ name: 'role_id', type: 'uuid' },
{ name: 'permission_id', type: 'uuid' },
],
}),
);
await queryRunner.createForeignKey(
'permissions_roles',
new TableForeignKey({
columnNames: ['permission_id'],
referencedColumnNames: ['id'],
referencedTableName: 'permissions',
name: 'fk_permissions_roles_',
onDelete: 'CASCADE',
onUpdate: 'SET NULL',
}),
);
await queryRunner.createForeignKey(
'permissions_roles',
new TableForeignKey({
columnNames: ['role_id'],
referencedColumnNames: ['id'],
referencedTableName: 'roles',
name: 'fk_roles_permissions',
onDelete: 'CASCADE',
onUpdate: 'SET NULL',
}),
);
}
Example #6
Source File: 1607024183135-AddUserIdToAppointments.ts From gobarber-project with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.addColumn(
'appointments',
new TableColumn({
name: 'user_id',
type: 'uuid',
isNullable: true,
}),
);
await queryRunner.createForeignKey(
'appointments',
new TableForeignKey({
name: 'AppointmentUser',
columnNames: ['user_id'],
referencedColumnNames: ['id'],
referencedTableName: 'users',
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
}),
);
}
Example #7
Source File: 1605815266154-AlterProviderFieldProviderId.ts From gobarber-project with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropColumn('appointments', 'provider');
await queryRunner.addColumn(
'appointments',
new TableColumn({
name: 'provider_id',
type: 'uuid',
isNullable: true,
}),
);
await queryRunner.createForeignKey(
'appointments',
new TableForeignKey({
name: 'AppointmentProvider',
columnNames: ['provider_id'],
referencedColumnNames: ['id'],
referencedTableName: 'users',
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
}),
);
}
Example #8
Source File: 1594569653170-AddCustomerIdToAppointment.ts From hotseat-api with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.addColumn(
'appointments',
new TableColumn({
name: 'customer_id',
type: 'uuid',
isNullable: true,
}),
);
await queryRunner.createForeignKey(
'appointments',
new TableForeignKey({
name: 'appointment_customer_id',
columnNames: ['customer_id'],
referencedColumnNames: ['id'],
referencedTableName: 'users',
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
}),
);
}
Example #9
Source File: 1589651808567-RelationUserAppointments.ts From hotseat-api with MIT License | 6 votes |
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.changeColumn(
'appointments',
'provider',
new TableColumn({
name: 'provider_id',
type: 'uuid',
isNullable: true,
}),
);
const providerForeignKey = new TableForeignKey({
name: 'appointments_provider',
columnNames: ['provider_id'],
referencedColumnNames: ['id'],
referencedTableName: 'users',
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
});
await queryRunner.createForeignKey('appointments', providerForeignKey);
}
Example #10
Source File: 1552371397992-AddCustomerWishlistRelationToCustomerTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_wishlist_customer',
columnNames: ['customer_id'],
referencedColumnNames: ['id'],
referencedTableName: 'customer',
onDelete: 'CASCADE',
});
Example #11
Source File: 1552371852472-AddCustomerWishlistRelationToProductTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_wishlist_product',
columnNames: ['product_id'],
referencedColumnNames: ['product_id'],
referencedTableName: 'product',
onDelete: 'CASCADE',
});
Example #12
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 #13
Source File: 1565087039728-DropFKforOrderCustomer.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_order_customer1',
columnNames: ['customer_id'],
referencedColumnNames: ['id'],
referencedTableName: 'customer',
onDelete: 'CASCADE',
});
Example #14
Source File: 1546602183498-CreateBannerGroupRelationToBannerTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_BannerGroup_Banner',
columnNames: ['banner_group_id'],
referencedColumnNames: ['banner_group_id'],
referencedTableName: 'banner_group',
onDelete: 'CASCADE',
});
Example #15
Source File: 1546594752832-AddOrderRelationToCustomerTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_order_customer1',
columnNames: ['customer_id'],
referencedColumnNames: ['id'],
referencedTableName: 'customer',
onDelete: 'CASCADE',
});
Example #16
Source File: 1546594411489-CreateBannerImageRelationToBannerImageDescriptionTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_BannerImage_BannerImageDescription',
columnNames: ['banner_image_id'],
referencedColumnNames: ['banner_image_id'],
referencedTableName: 'banner_image',
onDelete: 'CASCADE',
});
Example #17
Source File: 1546594262644-AddOrderHistoryRelationToOrderStatusTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_order_history_order_status1',
columnNames: ['order_status_id'],
referencedColumnNames: ['order_status_id'],
referencedTableName: 'order_status',
onDelete: 'CASCADE',
});
Example #18
Source File: 1546594184432-AddOrderHistoryRelationToOrderTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_order_history_order1',
columnNames: ['order_id'],
referencedColumnNames: ['order_id'],
referencedTableName: 'order',
onDelete: 'CASCADE',
});
Example #19
Source File: 1546594100673-CreatebannerRelationToBannerImageDescriptionTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_Banner_BannerImageDescription',
columnNames: ['banner_id'],
referencedColumnNames: ['banner_id'],
referencedTableName: 'banner',
onDelete: 'CASCADE',
});
Example #20
Source File: 1546593427323-CreateCategoryRelationToCategoryDescriptionTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_Category_CategoryDescription',
columnNames: ['category_id'],
referencedColumnNames: ['category_id'],
referencedTableName: 'category',
onDelete: 'CASCADE',
});
Example #21
Source File: 1546593359310-AddOrderProductRelationToOrderTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_order_product_order1',
columnNames: ['order_id'],
referencedColumnNames: ['order_id'],
referencedTableName: 'order',
onDelete: 'CASCADE',
});
Example #22
Source File: 1546593289549-AddOrderProductRelationToProductTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_order_product_product1',
columnNames: ['product_id'],
referencedColumnNames: ['product_id'],
referencedTableName: 'product',
onDelete: 'CASCADE',
});
Example #23
Source File: 1546593012207-AddCustomerTransactionRelationToCustomerTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_customer_transaction_customer1',
columnNames: ['customer_id'],
referencedColumnNames: ['id'],
referencedTableName: 'customer',
onDelete: 'CASCADE',
});
Example #24
Source File: 1546592870823-AddCustomerTransactionRelationToOrderTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_customer_transaction_order1',
columnNames: ['order_id'],
referencedColumnNames: ['order_id'],
referencedTableName: 'order',
onDelete: 'CASCADE',
});
Example #25
Source File: 1546590872444-AddPoductToCategoryRelationToCategoryTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_product_to_category_category1',
columnNames: ['category_id'],
referencedColumnNames: ['category_id'],
referencedTableName: 'category',
onDelete: 'CASCADE',
});
Example #26
Source File: 1546590433005-AddPoductToCategoryRelationToProductTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_product_to_category_product1',
columnNames: ['product_id'],
referencedColumnNames: ['product_id'],
referencedTableName: 'product',
onDelete: 'CASCADE',
});
Example #27
Source File: 1546586351105-CreateZoneCountryRelationToZoneGeoTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_Zone_ZoneGeo',
columnNames: ['zone_id'],
referencedColumnNames: ['zone_id'],
referencedTableName: 'zone',
onDelete: 'CASCADE',
});
Example #28
Source File: 1546585572765-AddPageRelationToPageGroupTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_page_page_group1',
columnNames: ['page_group_id'],
referencedColumnNames: ['page_group_id'],
referencedTableName: 'page_group',
onDelete: 'CASCADE',
});
Example #29
Source File: 1546585163896-AddProductImageRelationToProductTable.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 5 votes |
private tableForeignKey = new TableForeignKey({
name: 'fk_product_image_product1',
columnNames: ['product_id'],
referencedColumnNames: ['product_id'],
referencedTableName: 'product',
onDelete: 'CASCADE',
});