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

Wrap table name in quotes for dialect: postgres #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

None yet

1 participant