question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

synchronize=true in connection does not update database schema in DB

See original GitHub issue

Issue Description

Setting synchronize: true in createConnection does not update schema in DB (postgres 9.6) if there has been any change in entity schema after table is created. This issue occured in 0.2.34, 0.2.35. Issue does not exist in 0.2.33.

Expected Behavior

With synchronize: true, any change in entity should be updated in related database table.

Actual Behavior

With synchronize: true, table is created if it does not exist, but any further change in entity schema do not lead to change in database table.

Steps to Reproduce

  1. Set synchronize=true in createConnection option
  2. Update entity schema (e.g. adding a index) for a entity for which table already exits in database
  3. The entity schema update is not reflected in database table (e.g Newly added index is not created in database).
// Options used for creating connection
const conn = await createConnection({
                type: 'postgres',
                host: process.env.DB_HOST as string,
                port: parseInt(process.env.DB_PORT as string, 10),
                username: process.env.DB_USERNAME as string,
                password: process.env.DB_PASSWORD as string,
                database: process.env.DB_NAME as string,
                schema: 'public',
                logging: true,
                entities,
                namingStrategy: new SnakeNamingStrategy(),
                synchronize: true,
            });

My Environment

Dependency Version
Operating System MacOS Intel Big Sur 11.5
Node.js version 14.17.3
Typescript version 4.3.5
TypeORM version 0.2.35

Additional Context

Issue does not exist in version 0.2.33. Noticed in 0.2.34 and 0.2.35.

Relevant Database Driver(s)

DB Type Reproducible
aurora-data-api no
aurora-data-api-pg no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres yes
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✅ Yes, I have the time, but I don’t know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
rhummelmosecommented, Sep 15, 2022

Yep this isn’t working. Would be nice to get this fixed 😃

2reactions
pleerockcommented, Aug 2, 2021

Confirmed. Temporary solution is to remove schema: 'public', - by default it is already public and you can omit it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The database schema is not in sync with the current mapping ...
Run this command to show the differences in the SQL without having to dump your db: php bin/console doctrine:schema:update --dump-sql.
Read more >
Migrations Over Synchronize in TypeORM | by Uthpala Pitawela
First of all, you need to check whether the “synchronize” attribute of ormconfig.json is set to true. This is the entity and database...
Read more >
FAQ - typeorm - GitBook
How do I update a database schema? · Use synchronize: true in data source options: import { DataSource } from "typeorm". ​. const...
Read more >
DbSchema Schema Synchronization
Synchronize the Model with any Database · Select the Refresh button from the upper tool menu; · If your schema is not synchronized,...
Read more >
Schema is not updating – IDEs Support (IntelliJ Platform)
Four selections above the 'Synchronize' on your screenshot, there is Database Tools -> Manage Shown Schemas... then check if the schemata you ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found