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

[Postgres] Fails to drop indexes when changing fields #192

Closed
lktvlm opened this issue Jan 11, 2017 · 2 comments
Closed

[Postgres] Fails to drop indexes when changing fields #192

lktvlm opened this issue Jan 11, 2017 · 2 comments
Labels

Comments

@lktvlm
Copy link

lktvlm commented Jan 11, 2017

Tried the first sample.
First run correctly created a table.
After changing title: string; and text: string; to @column("text") typeorm failed to recreate its own indexes:

  • executing query: SELECT * FROM information_schema.tables WHERE table_catalog = 'test' AND table_schema = 'public'
  • executing query: SELECT * FROM information_schema.columns WHERE table_catalog = 'test' AND table_schema = 'public'
  • executing query: SELECT t.relname AS table_name, i.relname AS index_name, a.attname AS column_name FROM pg_class t, pg_class i, pg_index ix, pg_attribute a
  • WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid
  • AND a.attnum = ANY(ix.indkey) AND t.relkind = 'r' AND t.relname IN ('type_test_post') ORDER BY t.relname, i.relname
  • executing query: SELECT table_name, constraint_name FROM information_schema.table_constraints WHERE table_catalog = 'test' AND constraint_type = 'FOREIGN KEY'
  • executing query: SELECT * FROM information_schema.table_constraints WHERE table_catalog = 'test' AND constraint_type = 'UNIQUE'
  • executing query: SELECT c.column_name, tc.table_name, tc.constraint_name FROM information_schema.table_constraints tc
  • JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
  • JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema AND tc.table_name = c.table_name AND ccu.column_name = c.column_name
  • where constraint_type = 'PRIMARY KEY' and tc.table_catalog = 'test'
  • executing query: START TRANSACTION
  • columns changed in type_test_post. updating: title, text
  • dropping related indices of type_test_post#title: ind_d8ff91f7221b6df7c5b684ffa9cf3239b9baf4ed, my_index_with_id_and_title
  • executing query: ALTER TABLE "type_test_post" DROP CONSTRAINT "ind_d8ff91f7221b6df7c5b684ffa9cf3239b9baf4ed"
  • executing query: ALTER TABLE "type_test_post" DROP CONSTRAINT "my_index_with_id_and_title"
  • query failed: ALTER TABLE "type_test_post" DROP CONSTRAINT "ind_d8ff91f7221b6df7c5b684ffa9cf3239b9baf4ed"
  • query failed: ALTER TABLE "type_test_post" DROP CONSTRAINT "my_index_with_id_and_title"
  • executing query: ROLLBACK
  • Cannot connect: { error: constraint "ind_d8ff91f7221b6df7c5b684ffa9cf3239b9baf4ed" of relation "type_test_post" does not exist

Correct way to drop indexes in postgres is
DROP INDEX "ind_d8ff91f7221b6df7c5b684ffa9cf3239b9baf4ed"
NOT
ALTER TABLE "type_test_post" DROP CONSTRAINT "ind_d8ff91f7221b6df7c5b684ffa9cf3239b9baf4ed"

@pleerock
Copy link
Member

you are right, this is a bug. Fixed in 0.0.7-alpha.7, do npm i typeorm@0.0.7-alpha.7 to try it. Thank you for the report.

@lktvlm
Copy link
Author

lktvlm commented Jan 13, 2017

Yup, works ok now, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants