11 changed files with 141 additions and 3 deletions
@ -0,0 +1,39 @@ |
|||
'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,24 @@ |
|||
'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; |
|||
}; |
|||
@ -0,0 +1,16 @@ |
|||
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