GithubHelp home page GithubHelp logo

Comments (18)

kevin-lot avatar kevin-lot commented on June 1, 2024 3

I did that: #194
Some reviews are welcome.

from typeorm-fixtures.

RobinCK avatar RobinCK commented on June 1, 2024 1

[email protected]

from typeorm-fixtures.

imnotjames avatar imnotjames commented on June 1, 2024

TypeORM 0.3.0 isn't exactly backwards compatible, wouldn't that cause breakage?

from typeorm-fixtures.

glen-84 avatar glen-84 commented on June 1, 2024

@imnotjames True, I've updated the title and description to reflect the actual request.

from typeorm-fixtures.

maximelafarie avatar maximelafarie commented on June 1, 2024

@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.

glen-84 avatar glen-84 commented on June 1, 2024

@maximelafarie I haven't.

from typeorm-fixtures.

ovitaliw avatar ovitaliw commented on June 1, 2024

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.

christopheblin avatar christopheblin commented on June 1, 2024

@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.

kevin-lot avatar kevin-lot commented on June 1, 2024

@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.

christopheblin avatar christopheblin commented on June 1, 2024

@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.

kevin-lot avatar kevin-lot commented on June 1, 2024

@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.

christopheblin avatar christopheblin commented on June 1, 2024

@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.

kevin-lot avatar kevin-lot commented on June 1, 2024

@christopheblin

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.

kevin-lot avatar kevin-lot commented on June 1, 2024

@christopheblin

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.

christopheblin avatar christopheblin commented on June 1, 2024

@kevin-lot I'll try to create a repo with the issue and I will create a new issue

from typeorm-fixtures.

christopheblin avatar christopheblin commented on June 1, 2024

@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.

kevin-lot avatar kevin-lot commented on June 1, 2024

@christopheblin I'm currently running fixtures and migrations with only one datasource (and no options).

from typeorm-fixtures.

christopheblin avatar christopheblin commented on June 1, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.