Skip to content

Comments

Wrap table name in quotes for dialect: postgres#3

Open
anders0l wants to merge 1 commit intokimjbstar:masterfrom
anders0l:patch-1
Open

Wrap table name in quotes for dialect: postgres#3
anders0l wants to merge 1 commit intokimjbstar:masterfrom
anders0l:patch-1

Conversation

@anders0l
Copy link

There is known issue with postresql.
When table name is not wrapped in double quotes - postgres tries to find name in lower case.
'SELECT name FROM SequelizeMeta ORDER BY name desc limit 1' shows an error: relation "sequelizemeta" does not exist. But SequelizeMeta table exists.

There is known issue with postresql.
When table name is not wrapped in double quotes - postgres tries to find name in lower case.
'SELECT name FROM SequelizeMeta ORDER BY name desc limit 1' shows an error: relation "sequelizemeta" does not exist. But SequelizeMeta table exists.
@anders0l
Copy link
Author

Hot ugly fix that creates extra tables with lowercase:
createMigrationTable.ts

import { Sequelize, DataType } from 'sequelize-typescript'

export default async (sequelize: Sequelize) => {
	const queryInterface = sequelize.getQueryInterface()
	await queryInterface.createTable('sequelizemeta', {
		name: {
			type: DataType.STRING,
			allowNull: false,
			unique: true,
			primaryKey: true,
		},
	})
	await queryInterface.createTable('sequelizemetamigrations', {
		revision: {
			type: DataType.INTEGER,
			allowNull: false,
			unique: true,
			primaryKey: true,
		},
		name: {
			type: DataType.STRING,
			allowNull: false,
		},
		state: {
			type: DataType.JSON,
			allowNull: false,
		},
	})
}

Then in migration file add

await createMigrationTable(sequelize)

before

await SequelizeTypescriptMigration.makeMigration(sequelize, {

mricharz added a commit to mricharz/sequelize-typescript-migration that referenced this pull request Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant