2017-07-24 23:14:17 +00:00
|
|
|
const shareableEntityTypes = ['list', 'report', 'report_template', 'namespace'];
|
2017-05-15 20:22:06 +00:00
|
|
|
|
|
|
|
exports.up = function(knex, Promise) {
|
2017-07-24 23:14:17 +00:00
|
|
|
let schema = knex.schema;
|
|
|
|
|
|
|
|
for (const entityType of shareableEntityTypes) {
|
|
|
|
schema = schema
|
|
|
|
.createTable(`shares_${entityType}`, table => {
|
|
|
|
table.increments('id').primary();
|
|
|
|
table.integer('entity').unsigned().notNullable().references(`${entityType}s.id`).onDelete('CASCADE');
|
|
|
|
table.integer('user').unsigned().notNullable().references('users.id').onDelete('CASCADE');
|
|
|
|
table.string('role', 64).notNullable();
|
|
|
|
table.unique(['entity', 'user']);
|
|
|
|
})
|
|
|
|
.createTable(`permissions_${entityType}`, table => {
|
|
|
|
table.increments('id').primary();
|
|
|
|
table.integer('entity').unsigned().notNullable().references(`${entityType}s.id`).onDelete('CASCADE');
|
|
|
|
table.integer('user').unsigned().notNullable().references('users.id').onDelete('CASCADE');
|
|
|
|
table.string('operation', 64).notNullable();
|
|
|
|
table.unique(['entity', 'user', 'operation']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
schema = schema.then(() => knex('shares_namespace').insert({
|
2017-05-15 20:22:06 +00:00
|
|
|
id: 1,
|
2017-07-09 13:41:53 +00:00
|
|
|
entity: 1,
|
2017-05-15 20:22:06 +00:00
|
|
|
user: 1,
|
2017-07-09 13:41:53 +00:00
|
|
|
role: 'master'
|
2017-07-24 23:14:17 +00:00
|
|
|
}));
|
2017-05-15 20:22:06 +00:00
|
|
|
|
2017-07-24 23:14:17 +00:00
|
|
|
return schema;
|
2017-05-15 20:22:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.down = function(knex, Promise) {
|
2017-07-24 23:14:17 +00:00
|
|
|
let schema = knex.schema;
|
|
|
|
|
|
|
|
for (const entityType of shareableEntityTypes) {
|
|
|
|
schema = schema
|
|
|
|
.dropTable(`shares_${entityType}`)
|
|
|
|
.dropTable(`permissions_${entityType}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return schema;
|
2017-05-15 20:22:06 +00:00
|
|
|
};
|