12 changed files with 119 additions and 92 deletions
@ -1,39 +0,0 @@ |
|||
'use strict'; |
|||
/** @type {import('sequelize-cli').Migration} */ |
|||
module.exports = { |
|||
async up(queryInterface, Sequelize) { |
|||
await queryInterface.createTable('UsersRacers', { |
|||
userId: { |
|||
primaryKey: true, |
|||
type: Sequelize.STRING, |
|||
references: { |
|||
model: { |
|||
tableName: 'Users', |
|||
}, |
|||
key: 'auth0id', |
|||
}, |
|||
}, |
|||
racerId: { |
|||
primaryKey: true, |
|||
type: Sequelize.NUMBER, |
|||
references: { |
|||
model: { |
|||
tableName: 'Racers', |
|||
}, |
|||
key: 'id', |
|||
}, |
|||
}, |
|||
createdAt: { |
|||
allowNull: false, |
|||
type: Sequelize.DATE |
|||
}, |
|||
updatedAt: { |
|||
allowNull: false, |
|||
type: Sequelize.DATE |
|||
} |
|||
}); |
|||
}, |
|||
async down(queryInterface, Sequelize) { |
|||
await queryInterface.dropTable('UsersRacers'); |
|||
} |
|||
}; |
|||
@ -0,0 +1,68 @@ |
|||
'use strict'; |
|||
|
|||
/** @type {import('sequelize-cli').Migration} */ |
|||
module.exports = { |
|||
async up (queryInterface, Sequelize) { |
|||
/** |
|||
* Add altering commands here. |
|||
* |
|||
* Example: |
|||
* await queryInterface.createTable('users', { id: Sequelize.INTEGER }); |
|||
*/ |
|||
const transaction = await queryInterface.sequelize.transaction(); |
|||
try { |
|||
await queryInterface.addColumn( |
|||
'Users', |
|||
'tmRacerId', |
|||
{ |
|||
allowNull: true, |
|||
type: Sequelize.NUMBER, |
|||
references: { |
|||
model: { |
|||
tableName: 'Racers', |
|||
}, |
|||
key: 'id', |
|||
}, |
|||
}, |
|||
{ transaction } |
|||
); |
|||
await queryInterface.addColumn( |
|||
'Racers', |
|||
'userId', |
|||
{ |
|||
allowNull: true, |
|||
type: Sequelize.STRING, |
|||
references: { |
|||
model: { |
|||
tableName: 'Users', |
|||
}, |
|||
key: 'auth0id', |
|||
}, |
|||
}, |
|||
{ transaction } |
|||
); |
|||
await transaction.commit(); |
|||
} catch (err) { |
|||
await transaction.rollback(); |
|||
throw err; |
|||
} |
|||
}, |
|||
|
|||
async down (queryInterface, Sequelize) { |
|||
/** |
|||
* Add reverting commands here. |
|||
* |
|||
* Example: |
|||
* await queryInterface.dropTable('users'); |
|||
*/ |
|||
const transaction = await queryInterface.sequelize.transaction(); |
|||
try { |
|||
await queryInterface.removeColumn('Users', 'tmRacerId', { transaction }); |
|||
await queryInterface.removeColumn('Racers', 'userId', { transaction }); |
|||
await transaction.commit(); |
|||
} catch (err) { |
|||
await transaction.rollback(); |
|||
throw err; |
|||
} |
|||
} |
|||
}; |
|||
@ -1,24 +0,0 @@ |
|||
'use strict'; |
|||
const { |
|||
Model |
|||
} = require('sequelize'); |
|||
module.exports = (sequelize, DataTypes) => { |
|||
class UsersRacer extends Model { |
|||
/** |
|||
* Helper method for defining associations. |
|||
* This method is not a part of Sequelize lifecycle. |
|||
* The `models/index` file will call this method automatically. |
|||
*/ |
|||
static associate(models) { |
|||
// define association here
|
|||
} |
|||
} |
|||
UsersRacer.init({ |
|||
racerId: DataTypes.NUMBER, |
|||
userId: DataTypes.STRING |
|||
}, { |
|||
sequelize, |
|||
modelName: 'UsersRacer', |
|||
}); |
|||
return UsersRacer; |
|||
}; |
|||
@ -1,16 +0,0 @@ |
|||
import { Column, ForeignKey, HasMany, Model, PrimaryKey, Table } from "sequelize-typescript"; |
|||
import { Racer } from "src/racers/racer.model"; |
|||
import { User } from "./users.model"; |
|||
|
|||
@Table |
|||
export class UsersRacer extends Model { |
|||
@ForeignKey(() => User) |
|||
@PrimaryKey |
|||
@Column |
|||
userId: string; |
|||
|
|||
@ForeignKey(() => Racer) |
|||
@PrimaryKey |
|||
@Column |
|||
racerId: number; |
|||
} |
|||
Loading…
Reference in new issue