Skip to content

Conversation

@MaxGabriel
Copy link
Member

@MaxGabriel MaxGabriel commented Dec 19, 2017

My use case is that I have a database not using Persistent for migrations, and I want to use persistent to interact with it. I would also like to check that Persistent's models match the database schema by running getMigration and ensuring there are no changes to be made, but if there are spurious migrations then I'll have false positives.

In this database, text is being used instead of varchar, so Persistent claims it needs migrations. Since text and varchar are synonyms, this should be unnecessary.

Edit:

I found another, similar issue where Persistent would try to migrate a domained type to itself. This needed all the same test infrastructure and has the same theme, so I added it here. This is documented extensively in the comments; see there for details.

* These types are synonyms, with the exact same memory representation in Postgres
* So there's no need to suggest migrating from one to the other https://stackoverflow.com/a/4849030/1176156
@MaxGabriel MaxGabriel force-pushed the dontMigrateTextToVarchar branch from 88f9efa to 12e82a2 Compare December 19, 2017 00:04
Postgres supports the concept of domains, which are data types with optional constraints.
An app might make an "email" domain over the varchar type, with a CHECK that the emails are valid
In this case the generated SQL should use the domain name: ALTER TABLE users ALTER COLUMN foo TYPE email

Previously the migration code only looked at the underlying type (varchar), and tried to migrate something already of the domain email back to an email.
@MaxGabriel MaxGabriel changed the title Don't migrate between text and varchar in Postgres Don't migrate between text and varchar in Postgres / domains Dec 19, 2017
type SafeToRemove = Bool

data AlterColumn = Type SqlType Text
data AlterColumn = ChangeType SqlType Text
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the course of debugging this issue I found it extremely hard to search for Type, so I renamed this to ChangeType.

@MaxGabriel MaxGabriel merged commit 5af8670 into master Jan 4, 2018
@MaxGabriel MaxGabriel deleted the dontMigrateTextToVarchar branch January 4, 2018 22:23
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.

2 participants