Comments (18)
I did that: #194
Some reviews are welcome.
from typeorm-fixtures.
from typeorm-fixtures.
TypeORM 0.3.0 isn't exactly backwards compatible, wouldn't that cause breakage?
from typeorm-fixtures.
@imnotjames True, I've updated the title and description to reflect the actual request.
from typeorm-fixtures.
@glen-84 since there's no answer since you created this issue, have you come up with another solution that supports typeorm 0.3.x ?
from typeorm-fixtures.
@maximelafarie I haven't.
from typeorm-fixtures.
I created another ormconfig file with the typeorm v 0.2 specs and I use this file to run the typeorm-fixtures
from typeorm-fixtures.
@RobinCK let's say that I have a file named orm-config.ts in my source code
const options: PostgresConnectionOptions = {
type: 'postgres',
url: 'xxx',
synchronize: false,
entities: [...],
migrations: [...],
});
export default options;
At the moment, to use typeorm migrations, I am required to create a orm-datasource.ts with something like
import { DataSource } from 'typeorm';
import DATASOURCE_OPTIONS from './ormconfig';
export const DATASOURCE = new DataSource(DATASOURCE_OPTIONS);
Would it be possible somehow to work like the migrations and to use the datasource directly (instead of creating the datasource form the options) ?
Otherwise said, we should have consistent CLI with the typeorm in order to only have a single file orm-datasource.ts
typeorm -d src/ormdatasource.ts migration:run
fixtures ./test/fixtures/typeorm --sync --dataSource src/ormdatasource.ts
from typeorm-fixtures.
@christopheblin Otherwise said, we should have consistent CLI with the typeorm in order to only have a single file orm-datasource.ts
That's the goal, did you try it ?
from typeorm-fixtures.
@kevin-lot yes I did try it before posting my comment :)
fixtures ./test/fixtures/typeorm --sync --require=ts-node/register --require=tsconfig-paths/register --dataSource ./src/database/ormconfig.ts
Progress [██████████████████████████████████████████████████] 100% | ETA: 0s | 29/29
$ fixtures ./test/fixtures/typeorm --sync --require=ts-node/register --require=tsconfig-paths/register --dataSource ./src/database/ormdatasource.ts
Fail fixture loading: Wrong driver: "undefined" given. Supported drivers are: "aurora-mysql", "aurora-postgres", "better-sqlite3", "capacitor", "cockroachdb", "cordova", "expo", "mariadb", "mongodb", "mssql", "mysql", "nativescript", "oracle", "postgres", "react-native", "sap", "sqlite", "sqljs", "spanner".
MissingDriverError: Wrong driver: "undefined" given. Supported drivers are: "aurora-mysql", "aurora-postgres", "better-sqlite3", "capacitor", "cockroachdb", "cordova", "expo", "mariadb", "mongodb", "mssql", "mysql", "nativescript", "oracle", "postgres", "react-native", "sap", "sqlite", "sqljs", "spanner".
...
at typeorm-fixtures-cli/src/util/createConnection.ts:9:12
I think that https://github.com/RobinCK/typeorm-fixtures/pull/194/files#diff-eeaaf2a463a7b8738e67bea0c114825c52af230e7d11b59e431dcfe226d48540 is responsible for that
export async function createConnection(
config: { root?: string | undefined; configName?: string | undefined },
connectionName: string,
): Promise<DataSource> {
const options: DataSourceOptions = await new ConnectionOptionsReader(config).get(connectionName);
return new DataSource(options).initialize();
}
Or maybe something else, if you have any idea ?
from typeorm-fixtures.
@christopheblin I had this issue.
What's your url look like ?
url: postgres://login:pwd@localhost:5432/my_database
Or your url starts with postgresql
?
from typeorm-fixtures.
@kevin-lot I did that modification directly in the node_modules
function createConnection(config, connectionName) {
return __awaiter(this, void 0, void 0, function* () {
console.log(config, connectionName)
const options = yield new typeorm_1.ConnectionOptionsReader(config).get(connectionName);
console.log(options)
return new typeorm_1.DataSource(options).initialize();
});
}
Which outputs
{
root: '/Users/christopheblin/sources/excalibur/apps/graal/ticket/src/database',
configName: 'ormdatasource'
} default
{
DATASOURCE: <ref *1> DataSource {
'@instanceof': Symbol(DataSource),
migrations: [],
subscribers: [],
entityMetadatas: [],
name: 'default',
options: {
type: 'postgres',
url: 'postgres://root:root@db:5432/test',
synchronize: false,
entities: [Array],
migrations: [Array]
}
...
Fail fixture loading: Wrong driver: "undefined" given ...
It works if I change by a ugly
return "DATASOURCE" in options ? options.DATASOURCE.initialize() : new typeorm_1.DataSource(options).initialize();
-> I htink there really is something wrong in createConnection because it tries to new Datasource
on something that already contains a DataSource
from typeorm-fixtures.
I put the same console.log in the same file.
{
root: '/home/kevin/Documents/application/packages/api',
configName: 'datasource'
}
{
type: 'postgres',
url: 'postgres://postgres:postgres@localhost:5432/database_name',
host: undefined,
port: undefined,
username: undefined,
password: undefined,
database: undefined,
sid: undefined,
schema: undefined,
extra: undefined,
synchronize: false,
dropSchema: false,
migrationsRun: false,
entities: [ 'dist/**/*.entity.js' ],
migrations: [ 'dist/**/*-migrations.js' ],
migrationsTableName: undefined,
metadataTableName: undefined,
subscribers: [],
logging: true,
logger: undefined,
entityPrefix: undefined,
maxQueryExecutionTime: undefined,
debug: undefined,
cache: undefined,
uuidExtension: undefined,
baseDirectory: '/home/kevin/Documents/application/packages/api'
}
Our datasource.ts
import * as dotenv from 'dotenv';
import * as fs from 'fs';
import { DataSource } from 'typeorm';
< ...load dotenv... >
export const AppDataSource = new DataSource({
entities: process.env.TYPEORM_ENTITIES?.split(','),
logging: !!process.env.TYPEORM_LOGGING,
migrations: process.env.TYPEORM_MIGRATIONS?.split(','),
type: 'postgres',
url: process.env.TYPEORM_URL,
});
Without issue. :/
from typeorm-fixtures.
I read your connection configuration, you have an issue in it.
You put your configuration in the datasource.
Datasource has to build the configuration directly.
from typeorm-fixtures.
@kevin-lot I'll try to create a repo with the issue and I will create a new issue
from typeorm-fixtures.
@kevin-lot for info, I need to export both the options AND the datasource in order to use the datasource with migrations/fixtures and the options with nestjs/typeorm
from typeorm-fixtures.
@christopheblin I'm currently running fixtures and migrations with only one datasource (and no options).
from typeorm-fixtures.
@kevin-lot OK, I finally found it
I need noth DATASROUCE_OPTIONS and DATASOURCE because I am using migrations, fixtures and nestjs
In nestjs, I need to provide only the DATASOURCE_OPTIONS whereas in migrations and fixtures I need to provide DATASOURCE
-> so indeed the problem is not really in fixtures 👍
from typeorm-fixtures.
Related Issues (20)
- [Bug] Postgres 'timestamptz' column failing at parsing long date HOT 4
- [Bug] Update dependencies HOT 2
- [Bug] $current not working on array fields
- [Bug] class-validator entities may be incorrectly "unserialized/initialized" HOT 1
- [Bug] HOT 2
- [Bug] fix faker deprecation warning
- [Bug] Null ID when referencing another fixture HOT 1
- [Bug] glob is broken in Windows and cannot iterate by folder HOT 2
- [Feature request] Add support for regular expressions/glob patterns when setting fixtures location HOT 1
- [Bug]
- [Feature request] Add TsLoader for fixture
- Problem with @Exclude HOT 2
- [Feature request] Add faker examples with parameters in README
- [Feature request] Reference one field to generate another
- [Feature request] access to entity name in processor HOT 2
- [Feature request] Replace class-transformer usage with TypeORM Repository#merge
- [Bug] Limit faker version HOT 1
- [Feature request] Update `reflect-metadata` dependency to 0.2.2+
- Is this lib still maintained
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typeorm-fixtures.