104 lines
2.7 KiB
JavaScript
104 lines
2.7 KiB
JavaScript
const Sequelize = require("sequelize");
|
|
|
|
/**
|
|
* Actions summary:
|
|
*
|
|
* createTable() => "properties", deps: []
|
|
*
|
|
*/
|
|
|
|
const info = {
|
|
revision: 1,
|
|
name: "noname",
|
|
created: "2024-06-14T19:01:29.478Z",
|
|
comment: "",
|
|
};
|
|
|
|
const migrationCommands = (transaction) => [
|
|
{
|
|
fn: "createTable",
|
|
params: [
|
|
"properties",
|
|
{
|
|
id: {
|
|
type: Sequelize.STRING,
|
|
field: "id",
|
|
primaryKey: true,
|
|
unique: true,
|
|
allowNull: true,
|
|
},
|
|
title: { type: Sequelize.STRING, field: "title", allowNull: true },
|
|
url: { type: Sequelize.STRING, field: "url", allowNull: true },
|
|
price: { type: Sequelize.STRING, field: "price", allowNull: true },
|
|
rooms: { type: Sequelize.INTEGER, field: "rooms", allowNull: true },
|
|
area: { type: Sequelize.INTEGER, field: "area", allowNull: true },
|
|
level: { type: Sequelize.STRING, field: "level", allowNull: true },
|
|
description: {
|
|
type: Sequelize.TEXT,
|
|
field: "description",
|
|
allowNull: true,
|
|
},
|
|
pic: { type: Sequelize.TEXT, field: "pic", allowNull: true },
|
|
baths: { type: Sequelize.INTEGER, field: "baths", allowNull: true },
|
|
neighborhood: {
|
|
type: Sequelize.STRING,
|
|
field: "neighborhood",
|
|
allowNull: true,
|
|
},
|
|
phone: { type: Sequelize.STRING, field: "phone", allowNull: true },
|
|
createdAt: {
|
|
type: Sequelize.DATE,
|
|
field: "createdAt",
|
|
allowNull: false,
|
|
},
|
|
updatedAt: {
|
|
type: Sequelize.DATE,
|
|
field: "updatedAt",
|
|
allowNull: false,
|
|
},
|
|
},
|
|
{ transaction },
|
|
],
|
|
},
|
|
];
|
|
|
|
const rollbackCommands = (transaction) => [
|
|
{
|
|
fn: "dropTable",
|
|
params: ["properties", { transaction }],
|
|
},
|
|
];
|
|
|
|
const pos = 0;
|
|
const useTransaction = true;
|
|
|
|
const execute = (queryInterface, sequelize, _commands) => {
|
|
let index = pos;
|
|
const run = (transaction) => {
|
|
const commands = _commands(transaction);
|
|
return new Promise((resolve, reject) => {
|
|
const next = () => {
|
|
if (index < commands.length) {
|
|
const command = commands[index];
|
|
console.log(`[#${index}] execute: ${command.fn}`);
|
|
index++;
|
|
queryInterface[command.fn](...command.params).then(next, reject);
|
|
} else resolve();
|
|
};
|
|
next();
|
|
});
|
|
};
|
|
if (useTransaction) return queryInterface.sequelize.transaction(run);
|
|
return run(null);
|
|
};
|
|
|
|
module.exports = {
|
|
pos,
|
|
useTransaction,
|
|
up: (queryInterface, sequelize) =>
|
|
execute(queryInterface, sequelize, migrationCommands),
|
|
down: (queryInterface, sequelize) =>
|
|
execute(queryInterface, sequelize, rollbackCommands),
|
|
info,
|
|
};
|