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']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-26 19:42:05 +00:00
|
|
|
/* The global share for admin is set automatically in rebuild permissions, which is called upon every start */
|
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
|
|
|
};
|