Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing entityIdStrategy to UuidIdStrategy does not work #176

Closed
ghost opened this issue Oct 4, 2019 · 1 comment
Closed

Changing entityIdStrategy to UuidIdStrategy does not work #176

ghost opened this issue Oct 4, 2019 · 1 comment
Assignees
Labels
type: bug 🐛 Something isn't working

Comments

@ghost
Copy link

ghost commented Oct 4, 2019

Describe the bug
Changing entityIdStrategy to UuidIdStrategy does not work.

To Reproduce
Steps to reproduce the behavior:

  1. Create new PostgreSQL database.
  2. Add synchronize: true to your db settings:
    dbConnectionOptions: {
        type: 'postgres',
        synchronize: true,
        logging: false,
        database: 'vendure',
        host: '127.0.0.1',
        port: 5432,
        username: 'postgres',
        password: 'postgres',
    },
    entityIdStrategy: new UuidIdStrategy(),
  1. Run index.ts file with ts-node with several console.log statements:
$ ./node_modules/ts-node/dist/bin.js --version
v8.4.1
$ ./node_modules/ts-node/dist/bin.js index.ts
increment
bootstrap
preBootstrapConfig
setConfig
uuid
uuid
setConfig
uuid
info 10/4/19, 12:51 AM - [Vendure Server] Bootstrapping Vendure Server (pid: 82903)...
info 10/4/19, 12:51 AM - [NestApplication] Nest application successfully started
info 10/4/19, 12:51 AM - [Vendure Server] =================================================
info 10/4/19, 12:51 AM - [Vendure Server] Vendure server (v0.3.3) now running on port 3000
  1. Inspect generated db tables:
                                           Table "public.product"
     Column      |            Type             | Collation | Nullable |               Default
-----------------+-----------------------------+-----------+----------+-------------------------------------
 id              | integer                     |           | not null | nextval('product_id_seq'::regclass)
 createdAt       | timestamp without time zone |           | not null | now()
 updatedAt       | timestamp without time zone |           | not null | now()
 deletedAt       | timestamp without time zone |           |          |
 enabled         | boolean                     |           | not null | true
 featuredAssetId | integer                     |           |          |

Expected behavior
Changing entityIdStrategy to UuidIdStrategy should result in uuid type of id column of all tables which entities inherit from VendureEntity.

Environment (please complete the following information):

  • @vendure/core version:
    0.3.3
  • Nodejs version
    v10.16.3
  • Database (mysql/postgres etc):
    PostgreSQL 11
@ghost ghost added the type: bug 🐛 Something isn't working label Oct 4, 2019
@ghost ghost assigned michaelbromley Oct 4, 2019
@michaelbromley
Copy link
Member

This is because with the current implementation, the ID metadata that TypeORM uses is set as soon as the file containing the entity is evaluated. Up until now I have attempted to defer evaluation (i.e. importing) of the entity files until after the config has been set.

This is an error-prone approach, as evidenced by this issue! I am currently re-thinking how this can work so that no thought needs to be given to order of evaluation issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant