Beginning of work on templates.
This commit is contained in:
parent
47b8d80c22
commit
508d6b3b2f
40 changed files with 1685 additions and 1031 deletions
25
setup/knex/migrations/20180110120444_add_files.js
Normal file
25
setup/knex/migrations/20180110120444_add_files.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
const entityTypesWithFiles = ['template', 'campaign'];
|
||||
|
||||
exports.up = (knex, Promise) => (async() => {
|
||||
for (const entityType of entityTypesWithFiles) {
|
||||
|
||||
await knex.schema.createTable(`files_${entityType}`, table => {
|
||||
table.increments('id').primary();
|
||||
table.integer('entity').unsigned().notNullable().references('templates.id');
|
||||
table.string('filename');
|
||||
table.string('originalname');
|
||||
table.string('mimetype');
|
||||
table.string('encoding');
|
||||
table.integer('size');
|
||||
table.timestamp('created').defaultTo(knex.fn.now());
|
||||
table.index(['entity', 'originalname'])
|
||||
})
|
||||
|
||||
}
|
||||
})();
|
||||
|
||||
exports.down = (knex, Promise) => (async() => {
|
||||
for (const entityType of entityTypesWithFiles) {
|
||||
await knex.schema.dropTable(`files_${entityType}`);
|
||||
}
|
||||
})();
|
27
setup/knex/migrations/20180111120444_upgrade_templates.js
Normal file
27
setup/knex/migrations/20180111120444_upgrade_templates.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
exports.up = (knex, Promise) => (async() => {
|
||||
await knex.schema.table('templates', table => {
|
||||
table.json('data');
|
||||
table.string('type');
|
||||
});
|
||||
|
||||
const templates = await knex('templates');
|
||||
|
||||
for (const template of templates) {
|
||||
let type = template.editor_name;
|
||||
const data = JSON.parse(template.editor_data || '{}');
|
||||
|
||||
if (type == 'summernote') {
|
||||
type = 'ckeditor';
|
||||
}
|
||||
|
||||
await knex('templates').where('id', template.id).update({type, data: JSON.stringify(data)});
|
||||
}
|
||||
|
||||
await knex.schema.table('templates', table => {
|
||||
table.dropColumn('editor_name');
|
||||
table.dropColumn('editor_data');
|
||||
});
|
||||
})();
|
||||
|
||||
exports.down = (knex, Promise) => (async() => {
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue