Skip to content

Commit

Permalink
chore: add migration
Browse files Browse the repository at this point in the history
  • Loading branch information
kelp404 committed Jun 10, 2022
1 parent a3d466d commit a0c5fda
Show file tree
Hide file tree
Showing 2 changed files with 253 additions and 0 deletions.
141 changes: 141 additions & 0 deletions migrations/1-0.1.0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
'use strict';

const Sequelize = require('sequelize');

/**
* Actions summary:
*
* createTable "objects", deps: []
* addIndex "objects_dirname_type_basename_id" to table "objects"
* addIndex "objects_updated_at" to table "objects"
* addIndex "objects_path" to table "objects"
*
**/

const info = {
revision: 1,
name: '0.1.0',
created: '2022-06-10T02:52:38.046Z',
comment: '',
};

const migrationCommands = [{
fn: 'createTable',
params: [
'objects',
{
id: {
type: Sequelize.INTEGER,
field: 'id',
autoIncrement: true,
primaryKey: true,
allowNull: false,
},
type: {
type: Sequelize.TINYINT,
field: 'type',
validate: {
isIn: [
[1, 2],
],
},
allowNull: false,
},
path: {
type: Sequelize.STRING(1024),
field: 'path',
allowNull: false,
},
dirname: {
type: Sequelize.STRING(1024),
field: 'dirname',
allowNull: false,
},
basename: {
type: Sequelize.CITEXT,
field: 'basename',
allowNull: false,
},
lastModified: {
type: Sequelize.DATE,
field: 'lastModified',
defaultValue: Sequelize.NOW,
allowNull: false,
},
size: {
type: Sequelize.BIGINT,
field: 'size',
defaultValue: 0,
allowNull: false,
},
createdAt: {
type: Sequelize.DATE,
field: 'createdAt',
allowNull: false,
},
updatedAt: {
type: Sequelize.DATE,
field: 'updatedAt',
allowNull: false,
},
},
{},
],
},
{
fn: 'addIndex',
params: [
'objects',
['dirname', 'type', 'basename', 'id'],
{
indexName: 'objects_dirname_type_basename_id',
name: 'objects_dirname_type_basename_id',
},
],
},
{
fn: 'addIndex',
params: [
'objects',
['updatedAt'],
{
indexName: 'objects_updated_at',
name: 'objects_updated_at',
},
],
},
{
fn: 'addIndex',
params: [
'objects',
['path'],
{
indexName: 'objects_path',
name: 'objects_path',
indicesType: 'UNIQUE',
type: 'UNIQUE',
},
],
}];

module.exports = {
pos: 0,
up(queryInterface, Sequelize) {
let index = this.pos;
return new Promise((resolve, reject) => {
function next() {
if (index < migrationCommands.length) {
const command = migrationCommands[index];
console.log('[#' + index + '] execute: ' + command.fn);
index++;
queryInterface[command.fn].apply(queryInterface, command.params).then(next, reject);
} else {
resolve();
}
}

next();
});
},
info,
};
112 changes: 112 additions & 0 deletions migrations/_current.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"tables": {
"objects": {
"tableName": "objects",
"schema": {
"id": {
"allowNull": false,
"primaryKey": true,
"autoIncrement": true,
"field": "id",
"seqType": "Sequelize.INTEGER"
},
"type": {
"allowNull": false,
"validate": {
"isIn": [
[
1,
2
]
]
},
"field": "type",
"seqType": "Sequelize.TINYINT"
},
"path": {
"allowNull": false,
"field": "path",
"seqType": "Sequelize.STRING(1024)"
},
"dirname": {
"allowNull": false,
"field": "dirname",
"seqType": "Sequelize.STRING(1024)"
},
"basename": {
"allowNull": false,
"field": "basename",
"seqType": "Sequelize.CITEXT"
},
"lastModified": {
"allowNull": false,
"defaultValue": {
"internal": true,
"value": "Sequelize.NOW"
},
"field": "lastModified",
"seqType": "Sequelize.DATE"
},
"size": {
"allowNull": false,
"defaultValue": {
"value": 0
},
"field": "size",
"seqType": "Sequelize.BIGINT"
},
"createdAt": {
"allowNull": false,
"field": "createdAt",
"seqType": "Sequelize.DATE"
},
"updatedAt": {
"allowNull": false,
"field": "updatedAt",
"seqType": "Sequelize.DATE"
}
},
"indexes": {
"183f280b8914e4555e01bc7ea2b5a6d53968a206": {
"unique": true,
"fields": [
"path"
],
"name": "objects_path",
"options": {
"indexName": "objects_path",
"name": "objects_path",
"indicesType": "UNIQUE",
"type": "UNIQUE"
}
},
"3ec0abbcc3a1c6da61ddba1070d200bc91de5e23": {
"unique": false,
"fields": [
"updatedAt"
],
"name": "objects_updated_at",
"options": {
"indexName": "objects_updated_at",
"name": "objects_updated_at"
}
},
"bfeb9da4c77d8c67376eb7071c7003b1bc16f46e": {
"unique": false,
"fields": [
"dirname",
"type",
"basename",
"id"
],
"name": "objects_dirname_type_basename_id",
"options": {
"indexName": "objects_dirname_type_basename_id",
"name": "objects_dirname_type_basename_id"
}
}
}
}
},
"revision": 1
}

0 comments on commit a0c5fda

Please sign in to comment.