fix(database): migrations table name missing table prefix
This commit is contained in:
parent
a26ac4f217
commit
e0646650f0
@ -18,6 +18,10 @@ describe('migrator', () => {
|
|||||||
await db.close();
|
await db.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('migrations', async () => {
|
||||||
|
expect(db.getModel('migrations').tableName).toBe('test_migrations');
|
||||||
|
});
|
||||||
|
|
||||||
test('addMigrations', async () => {
|
test('addMigrations', async () => {
|
||||||
db.addMigrations({
|
db.addMigrations({
|
||||||
directory: resolve(__dirname, './fixtures/migrations'),
|
directory: resolve(__dirname, './fixtures/migrations'),
|
||||||
|
@ -62,13 +62,13 @@ import {
|
|||||||
} from './types';
|
} from './types';
|
||||||
import { patchSequelizeQueryInterface, snakeCase } from './utils';
|
import { patchSequelizeQueryInterface, snakeCase } from './utils';
|
||||||
|
|
||||||
import DatabaseUtils from './database-utils';
|
|
||||||
import { registerBuiltInListeners } from './listeners';
|
|
||||||
import { BaseValueParser, registerFieldValueParsers } from './value-parsers';
|
|
||||||
import buildQueryInterface from './query-interface/query-interface-builder';
|
|
||||||
import QueryInterface from './query-interface/query-interface';
|
|
||||||
import { Logger } from '@nocobase/logger';
|
import { Logger } from '@nocobase/logger';
|
||||||
import { CollectionGroupManager } from './collection-group-manager';
|
import { CollectionGroupManager } from './collection-group-manager';
|
||||||
|
import DatabaseUtils from './database-utils';
|
||||||
|
import { registerBuiltInListeners } from './listeners';
|
||||||
|
import QueryInterface from './query-interface/query-interface';
|
||||||
|
import buildQueryInterface from './query-interface/query-interface-builder';
|
||||||
|
import { BaseValueParser, registerFieldValueParsers } from './value-parsers';
|
||||||
import { ViewCollection } from './view-collection';
|
import { ViewCollection } from './view-collection';
|
||||||
|
|
||||||
export type MergeOptions = merge.Options;
|
export type MergeOptions = merge.Options;
|
||||||
@ -275,6 +275,12 @@ export class Database extends EventEmitter implements AsyncEmitter {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.sequelize.beforeDefine((model, opts) => {
|
||||||
|
if (this.options.tablePrefix) {
|
||||||
|
opts.tableName = `${this.options.tablePrefix}${opts.tableName || opts.modelName || opts.name.plural}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.collection({
|
this.collection({
|
||||||
name: 'migrations',
|
name: 'migrations',
|
||||||
autoGenId: false,
|
autoGenId: false,
|
||||||
@ -284,12 +290,6 @@ export class Database extends EventEmitter implements AsyncEmitter {
|
|||||||
fields: [{ type: 'string', name: 'name' }],
|
fields: [{ type: 'string', name: 'name' }],
|
||||||
});
|
});
|
||||||
|
|
||||||
this.sequelize.beforeDefine((model, opts) => {
|
|
||||||
if (this.options.tablePrefix) {
|
|
||||||
opts.tableName = `${this.options.tablePrefix}${opts.tableName || opts.modelName || opts.name.plural}`;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.initListener();
|
this.initListener();
|
||||||
patchSequelizeQueryInterface(this);
|
patchSequelizeQueryInterface(this);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,12 @@ import { Migration } from '@nocobase/server';
|
|||||||
|
|
||||||
export default class extends Migration {
|
export default class extends Migration {
|
||||||
async up() {
|
async up() {
|
||||||
|
const result = await this.app.version.satisfies('<0.9.3-alpha.1');
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await this.app.db.getRepository('roles').update({
|
await this.app.db.getRepository('roles').update({
|
||||||
filter: {
|
filter: {
|
||||||
$or: [{ allowConfigure: true }, { name: 'root' }],
|
$or: [{ allowConfigure: true }, { name: 'root' }],
|
||||||
|
@ -3,6 +3,12 @@ import { CollectionsGraph } from '@nocobase/utils';
|
|||||||
|
|
||||||
export default class extends Migration {
|
export default class extends Migration {
|
||||||
async up() {
|
async up() {
|
||||||
|
const result = await this.app.version.satisfies('<0.9.3-alpha.1');
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.app.db.getCollection('applications')) return;
|
if (!this.app.db.getCollection('applications')) return;
|
||||||
|
|
||||||
await this.app.db.getCollection('collections').repository.destroy({
|
await this.app.db.getCollection('collections').repository.destroy({
|
||||||
|
Loading…
Reference in New Issue
Block a user