fix: DB_TABLE_PREFIX doesn't get applied (#710)

* fix: env DB_TABLE_PREFIX doesn't get applied

* fix: remove before define

* fix: test error

* fix: table prefix

* test: ci

* fix: test error

* test: ci

* test: ci

* fix: test error

* fix: test error

* chore: update node ci
This commit is contained in:
chenos 2022-08-04 21:27:55 +08:00 committed by GitHub
parent f4f35bdb43
commit cec5733260
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 9 deletions

View File

@ -40,7 +40,7 @@ jobs:
node-version: ${{ matrix.node_version }}
cache: 'yarn'
- run: yarn install
- run: yarn build
# - run: yarn build
- name: Test with postgres
run: yarn test
env:

View File

@ -10,4 +10,5 @@ export default {
host: process.env.DB_HOST,
port: process.env.DB_PORT as any,
timezone: process.env.DB_TIMEZONE,
tablePrefix: process.env.DB_TABLE_PREFIX,
} as IDatabaseOptions;

View File

@ -390,7 +390,7 @@ describe('update associations', () => {
afterEach(async () => {
await db.close();
});
test.only('set through value', async () => {
test('set through value', async () => {
const p1 = await Post.repository.create({
values: {
title: 'hello',

View File

@ -135,7 +135,7 @@ export class Database extends EventEmitter implements AsyncEmitter {
},
force: false,
},
...options,
...lodash.clone(options),
};
if (options.storage && options.storage !== ':memory:') {
@ -197,6 +197,12 @@ export class Database extends EventEmitter implements AsyncEmitter {
sequelize: this.sequelize,
}),
});
this.sequelize.beforeDefine((model, opts) => {
if (this.options.tablePrefix) {
opts.tableName = `${this.options.tablePrefix}${opts.tableName || opts.modelName || opts.name.plural}`;
}
});
}
addMigration(item) {

View File

@ -10,9 +10,6 @@ export class MockDatabase extends Database {
dialect: 'sqlite',
...options,
});
this.sequelize.beforeDefine((model, opts) => {
opts.tableName = `${this.getTablePrefix()}${opts.tableName || opts.modelName || opts.name.plural}`;
});
}
}

View File

@ -1,7 +1,7 @@
import { mockServer, MockServer } from '@nocobase/test';
import { Database } from '@nocobase/database';
import { PluginMultiAppManager } from '../server';
import { mockServer, MockServer } from '@nocobase/test';
import { ApplicationModel } from '..';
import { PluginMultiAppManager } from '../server';
describe('multiple apps create', () => {
let app: MockServer;

View File

@ -99,7 +99,10 @@ export class ApplicationModel extends Model {
}
return {
database: rawDatabaseOptions,
database: {
...rawDatabaseOptions,
tablePrefix: '',
},
};
}
}