Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit adf95ea

Browse files
committed
update migrations & add TCSkills
1 parent 47225cc commit adf95ea

File tree

6 files changed

+84
-19
lines changed

6 files changed

+84
-19
lines changed

scripts/db/migrations.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
const sequelize = require('../../src/models/index')
22
const path = require('path')
3-
const Umzug = require('umzug')
3+
const { Umzug, SequelizeStorage } = require('umzug')
44

55
function getUmzug () {
66
return new Umzug({
77
migrations: {
8-
// indicates the folder containing the migration .js files
9-
path: path.join(__dirname, './migrations'),
8+
glob: path.join(__dirname, './migrations/*.js'),
109
// inject sequelize's QueryInterface in the migrations
1110
params: [
1211
sequelize.getQueryInterface()
1312
]
1413
},
14+
context: sequelize.getQueryInterface(),
1515
// indicates that the migration data should be store in the database
1616
// itself through sequelize. The default configuration creates a table
1717
// named `SequelizeMeta`.
18-
storage: 'sequelize',
19-
storageOptions: {
20-
sequelize: sequelize
21-
}
18+
storage: new SequelizeStorage({ sequelize })
2219
})
2320
}
2421

scripts/db/migrations/01-create-taxonomy.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const { DataTypes } = require('sequelize')
22

33
module.exports = {
4-
up: async (query) => {
5-
await query.createTable('Taxonomies', {
4+
up: async ({ context: queryInterface }) => {
5+
await queryInterface.createTable('Taxonomies', {
66
id: {
77
primaryKey: true,
88
type: DataTypes.UUID,
@@ -29,7 +29,7 @@ module.exports = {
2929
}
3030
})
3131
},
32-
down: async (query) => {
33-
await query.dropTable('Taxonomies')
32+
down: async ({ context: queryInterface }) => {
33+
await queryInterface.dropTable('Taxonomies')
3434
}
3535
}

scripts/db/migrations/02_create-skill.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const { DataTypes } = require('sequelize')
22

33
module.exports = {
4-
up: async (query) => {
5-
await query.createTable('Skills', {
4+
up: async ({ context: queryInterface }) => {
5+
await queryInterface.createTable('Skills', {
66
id: {
77
primaryKey: true,
88
type: DataTypes.UUID,
@@ -35,7 +35,7 @@ module.exports = {
3535
}
3636
})
3737
},
38-
down: async (query) => {
39-
await query.dropTable('Skills')
38+
down: async ({ context: queryInterface }) => {
39+
await queryInterface.dropTable('Skills')
4040
}
4141
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const { DataTypes } = require('sequelize')
22

33
module.exports = {
4-
up: async (query) => {
5-
await query.addColumn('Skills', 'taxonomyId', {
4+
up: async ({ context: queryInterface }) => {
5+
await queryInterface.addColumn('Skills', 'taxonomyId', {
66
type: DataTypes.UUID,
77
references: {
88
model: 'Taxonomies',
@@ -11,7 +11,7 @@ module.exports = {
1111
onUpdate: 'CASCADE'
1212
})
1313
},
14-
down: async (query) => {
15-
await query.removeColumn('Skills', 'taxonomyId')
14+
down: async ({ context: queryInterface }) => {
15+
await queryInterface.removeColumn('Skills', 'taxonomyId')
1616
}
1717
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const { DataTypes } = require('sequelize')
2+
3+
module.exports = {
4+
up: async ({ context: queryInterface }) => {
5+
6+
await queryInterface.createTable('TCSkills', {
7+
id: {
8+
primaryKey: true,
9+
type: DataTypes.UUID,
10+
defaultValue: DataTypes.UUIDV4
11+
},
12+
name: {
13+
type: DataTypes.STRING,
14+
allowNull: false
15+
},
16+
description: {
17+
type: DataTypes.TEXT
18+
},
19+
createdAt: {
20+
type: DataTypes.DATE,
21+
allowNull: false
22+
},
23+
updatedAt: {
24+
type: DataTypes.DATE
25+
}
26+
})
27+
28+
await queryInterface.addIndex('TCSkills', ['name'], {
29+
name: "TCSkill_name_key",
30+
unique: true,
31+
})
32+
33+
},
34+
down: async ({ context: queryInterface }) => {
35+
await queryInterface.dropTable('TCSkills')
36+
}
37+
}

src/models/TCSkill.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const { DataTypes } = require('sequelize')
2+
3+
module.exports = (sequelize) => {
4+
const TCSkill = sequelize.define('TCSkill', {
5+
id: {
6+
primaryKey: true,
7+
type: DataTypes.UUID,
8+
defaultValue: DataTypes.UUIDV4
9+
},
10+
name: {
11+
type: DataTypes.STRING,
12+
allowNull: false
13+
},
14+
description: {
15+
type: DataTypes.TEXT
16+
}
17+
},
18+
{
19+
timestamps: true,
20+
indexes: [
21+
{
22+
name: "TCSkill_name_key",
23+
unique: true,
24+
fields: [
25+
{ name: "name" },
26+
]
27+
},
28+
]
29+
})
30+
return TCSkill
31+
}

0 commit comments

Comments
 (0)