mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
5ef889addd
Summary: This moves enough server material into core to run a home server. The data engine is not yet incorporated (though in manual testing it works when ported). Test Plan: existing tests pass Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2552
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import {MigrationInterface, QueryRunner, Table, TableColumn, TableIndex} from 'typeorm';
|
|
import {datetime, now} from 'app/gen-server/sqlUtils';
|
|
|
|
export class Aliases1561589211752 implements MigrationInterface {
|
|
|
|
public async up(queryRunner: QueryRunner): Promise<any> {
|
|
const dbType = queryRunner.connection.driver.options.type;
|
|
|
|
// Make a table for document aliases.
|
|
await queryRunner.createTable(new Table({
|
|
name: 'aliases',
|
|
columns: [
|
|
{
|
|
name: 'url_id',
|
|
type: 'varchar',
|
|
isPrimary: true
|
|
},
|
|
{
|
|
name: 'org_id',
|
|
type: 'integer',
|
|
isPrimary: true
|
|
},
|
|
{
|
|
name: 'doc_id',
|
|
type: 'varchar',
|
|
isNullable: true // nullable in case in future we make aliases for other resources
|
|
},
|
|
{
|
|
name: "created_at",
|
|
type: datetime(dbType),
|
|
default: now(dbType)
|
|
}
|
|
],
|
|
foreignKeys: [
|
|
{
|
|
columnNames: ['doc_id'],
|
|
referencedColumnNames: ['id'],
|
|
referencedTableName: 'docs',
|
|
onDelete: 'CASCADE' // delete alias if doc goes away
|
|
},
|
|
{
|
|
columnNames: ['org_id'],
|
|
referencedColumnNames: ['id'],
|
|
referencedTableName: 'orgs'
|
|
// no CASCADE set - let deletions be triggered via docs
|
|
}
|
|
]
|
|
}));
|
|
|
|
// Add preferred alias to docs. Not quite a foreign key (we'd need org as well)
|
|
await queryRunner.addColumn('docs', new TableColumn({
|
|
name: 'url_id',
|
|
type: 'varchar',
|
|
isNullable: true
|
|
}));
|
|
await queryRunner.createIndex("docs", new TableIndex({
|
|
name: "docs__url_id",
|
|
columnNames: ["url_id"]
|
|
}));
|
|
}
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<any> {
|
|
await queryRunner.dropIndex('docs', 'docs__url_id');
|
|
await queryRunner.dropColumn('docs', 'url_id');
|
|
await queryRunner.dropTable('aliases');
|
|
}
|
|
}
|