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:
parent
f4f35bdb43
commit
cec5733260
2
.github/workflows/node-ci.yml
vendored
2
.github/workflows/node-ci.yml
vendored
@ -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:
|
||||
|
@ -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;
|
||||
|
@ -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',
|
||||
|
@ -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) {
|
||||
|
@ -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}`;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -99,7 +99,10 @@ export class ApplicationModel extends Model {
|
||||
}
|
||||
|
||||
return {
|
||||
database: rawDatabaseOptions,
|
||||
database: {
|
||||
...rawDatabaseOptions,
|
||||
tablePrefix: '',
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user