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 }}
|
node-version: ${{ matrix.node_version }}
|
||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
- run: yarn install
|
- run: yarn install
|
||||||
- run: yarn build
|
# - run: yarn build
|
||||||
- name: Test with postgres
|
- name: Test with postgres
|
||||||
run: yarn test
|
run: yarn test
|
||||||
env:
|
env:
|
||||||
|
@ -10,4 +10,5 @@ export default {
|
|||||||
host: process.env.DB_HOST,
|
host: process.env.DB_HOST,
|
||||||
port: process.env.DB_PORT as any,
|
port: process.env.DB_PORT as any,
|
||||||
timezone: process.env.DB_TIMEZONE,
|
timezone: process.env.DB_TIMEZONE,
|
||||||
|
tablePrefix: process.env.DB_TABLE_PREFIX,
|
||||||
} as IDatabaseOptions;
|
} as IDatabaseOptions;
|
||||||
|
@ -390,7 +390,7 @@ describe('update associations', () => {
|
|||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await db.close();
|
await db.close();
|
||||||
});
|
});
|
||||||
test.only('set through value', async () => {
|
test('set through value', async () => {
|
||||||
const p1 = await Post.repository.create({
|
const p1 = await Post.repository.create({
|
||||||
values: {
|
values: {
|
||||||
title: 'hello',
|
title: 'hello',
|
||||||
|
@ -135,7 +135,7 @@ export class Database extends EventEmitter implements AsyncEmitter {
|
|||||||
},
|
},
|
||||||
force: false,
|
force: false,
|
||||||
},
|
},
|
||||||
...options,
|
...lodash.clone(options),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.storage && options.storage !== ':memory:') {
|
if (options.storage && options.storage !== ':memory:') {
|
||||||
@ -197,6 +197,12 @@ export class Database extends EventEmitter implements AsyncEmitter {
|
|||||||
sequelize: this.sequelize,
|
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) {
|
addMigration(item) {
|
||||||
|
@ -10,9 +10,6 @@ export class MockDatabase extends Database {
|
|||||||
dialect: 'sqlite',
|
dialect: 'sqlite',
|
||||||
...options,
|
...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 { Database } from '@nocobase/database';
|
||||||
import { PluginMultiAppManager } from '../server';
|
import { mockServer, MockServer } from '@nocobase/test';
|
||||||
import { ApplicationModel } from '..';
|
import { ApplicationModel } from '..';
|
||||||
|
import { PluginMultiAppManager } from '../server';
|
||||||
|
|
||||||
describe('multiple apps create', () => {
|
describe('multiple apps create', () => {
|
||||||
let app: MockServer;
|
let app: MockServer;
|
||||||
|
@ -99,7 +99,10 @@ export class ApplicationModel extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
database: rawDatabaseOptions,
|
database: {
|
||||||
|
...rawDatabaseOptions,
|
||||||
|
tablePrefix: '',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user