mirror of
https://github.com/strapi/strapi.git
synced 2025-07-29 20:10:21 +00:00
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Module dependencies
|
|
*/
|
|
|
|
// Node.js core.
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Public node modules.
|
|
const _ = require('lodash');
|
|
|
|
/**
|
|
* Select table
|
|
*/
|
|
|
|
module.exports = function (models, modelName) {
|
|
|
|
models[modelName].up = {};
|
|
|
|
// Template: select the table for the `up` export.
|
|
// Every attribute with `create` key will be added in this template.
|
|
const tplSelectTableUp = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'tables', 'select', 'up.template'), 'utf8');
|
|
models[modelName].up.drop = _.unescape(_.template(tplSelectTableUp)({
|
|
models: models,
|
|
tableName: modelName,
|
|
attributes: models[modelName].newAttributes,
|
|
toDrop: true
|
|
}));
|
|
|
|
models[modelName].up.others = _.unescape(_.template(tplSelectTableUp)({
|
|
models: models,
|
|
tableName: modelName,
|
|
attributes: models[modelName].newAttributes,
|
|
toDrop: false
|
|
}));
|
|
|
|
models[modelName].down = {};
|
|
|
|
// Template: select the table for the `down` export.
|
|
// Every attribute with `delete` key will be added in this template.
|
|
const tplSelectTableDown = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'tables', 'select', 'down.template'), 'utf8');
|
|
models[modelName].down.drop = _.unescape(_.template(tplSelectTableDown)({
|
|
models: models,
|
|
tableName: modelName,
|
|
attributes: models[modelName].newAttributes,
|
|
toDrop: true
|
|
}));
|
|
|
|
models[modelName].down.others = _.unescape(_.template(tplSelectTableDown)({
|
|
models: models,
|
|
tableName: modelName,
|
|
attributes: models[modelName].newAttributes,
|
|
toDrop: false
|
|
}));
|
|
};
|