I'm trying to generate migration files for my entities, but whenever I run the command to create the entity, it creates an "empty" file, just the up and down methods are created.
I have added this script in my package.json file: "typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js".
In my app.module.ts, the connection is configured like this:
TypeOrmModule.forRoot({
type: 'mysql',
host: database().host,
port: parseInt(database().port),
username: database().username,
password: database().password,
database: database().schema,
entities: [Question, QuestionOption],
migrations: ['src/migration/*{.ts,.js}'],
cli: {
migrationsDir: 'src/migration'
},
synchronize: true,
})
Where database() it's a nestjs config file and get the values from an .env file.
The script I'm using to create the migration is: npm run typeorm migration:create -- -n QuestionTables -d src/migrations where need to specify the -d, otherwise the migration file is not created (even if it's specified in the cli of the forRoot method.
Do I need to write manually the SQL to create the tables?
What if I need to add a new column to an existing table, should I create a new migration file and write manually the SQL code to add that?
Another command that I tried to run was this one: npm run typeorm migration:generate -- -n QuestionTables -d src/migrations and here it gives me an error: " Error: No connection options were found in any orm configuration files."