tada5hi/typeorm-extension

Bug: Synchronize not working after DB creation, just times out

Divaaan opened this issue · 1 comments

Versions

  • Node: Node 16
  • OS: Linux (Azure App service)

Reproduction

Tried to set both synchronisation options to true but has 0 effect, tried increasing timeouts but still no effect. Not sure what else I can do?
Only workaround is to use this to create the database and use Typeorm's initialize function to sync the tables but it's not the greatest solution.

Also locally it works perfectly, syncs everything etc but not on the azure side.

await createDatabase({
        ifNotExist: true,
        synchronize: true,
        options: {
	        synchronize: true,
	        logging: true,
	        logger: 'file',
	        options: {
		        encrypt: true,
	        },
	        type: 'mssql',
	        host: process.env.DATABASE_HOST ?? 'localhost',
	        username: process.env.DATABASE_USERNAME ?? 'sa',
	        password: process.env.DATABASE_PASSWORD ?? 'Password01!',
	        database: `db-${site}`,
	        extra: (process.env.ENVIRONMENT === 'localhost') ? {
		        trustServerCertificate: true,
	        } : {},
	        entities: [...entities],
        },
})

Steps to reproduce

Not sure if it's only an azure thing but deploy to app service and then do the create database function with entities etc...

What is Expected?

Tables should be synchronised once DB is created

What is actually happening?

Timeout occurs even if request & connections timeouts have been increased. As if it's not using those values.

Hey @Divaaan ,
unfortunately I don't use azure and therefore can't reproduce the problem, but can you try if the follwoing code snippet is working for you?
But I understood you correctly that it works locally or?

import { DataSourceOptions } from 'typeorm';
import { createDatabase, setupDatabaseSchema, SeederOptions } from 'typeorm-extension';

const options : DataSourceOptions & SeederOptions = {
        synchronize: false,
        logging: true,
        logger: 'file',
        options: {
             encrypt: true,
        },
        type: 'mssql',
        host: process.env.DATABASE_HOST ?? 'localhost',
        username: process.env.DATABASE_USERNAME ?? 'sa',
        password: process.env.DATABASE_PASSWORD ?? 'Password01!',
        database: `db-${site}`,
        extra: (process.env.ENVIRONMENT === 'localhost') ? {
        trustServerCertificate: true,
        } : {},
        entities: [...entities],
}

await createDatabase({
        ifNotExist: true,
        synchronize: false,
        options,
});

await setupDatabaseSchema(options);