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

Downgrade sql script is wrong for renamed columns #122

Open
KES777 opened this issue Apr 30, 2019 · 1 comment
Open

Downgrade sql script is wrong for renamed columns #122

KES777 opened this issue Apr 30, 2019 · 1 comment

Comments

@KES777
Copy link

KES777 commented Apr 30, 2019

How to reproduce.

Change the definition of your column

@@ -57,9 +57,12 @@ $X->add_columns(
     suma => {
         data_type => 'tmoney',
     },
-    last_bill_date => {
+    billed_to => {
         data_type     => 'datetime',
         default_value => 'Infinity',
+        extra => {
+            renamed_from => 'last_bill_date',
+        },
     },
     comment => {
         data_type   => 'text',

produced SQL's for upgrade and downgrade:

Upgrade:

BEGIN;

;
ALTER TABLE "order" RENAME COLUMN "last_bill_date" TO "billed_to";

;

COMMIT;

Downgrade:

;
BEGIN;

;
ALTER TABLE "order" DROP COLUMN "billed_to";

;
ALTER TABLE "order" ADD COLUMN "last_bill_date" timestamp DEFAULT 'Infinity' NOT NULL;

;

COMMIT;
@KES777
Copy link
Author

KES777 commented May 4, 2019

Strange thing. After I upgrade my DB and remove info about migration:

@@ -60,9 +60,6 @@ $X->add_columns(
     billed_to => {
         data_type     => 'datetime',
         default_value => 'Infinity',
-        extra => {
-            renamed_from => 'last_bill_date',
-        },
     },
     comment => {
         data_type   => 'text',

I create next migration with some changes. (it has now matter which. Just add some field to any table for example). While doing that I get the warning:

Overwriting existing upgrade-diff file - /home/kes/work/projects/tucha/monkeyman/share/migrations/PostgreSQL/upgrade/129-130/001-auto.sql at /home/kes/work/projects/tucha/monkeyman/local/lib/perl5/DBIx/Class/DeploymentHandler/WithReasonableDefaults.pm line 18.

SQL::Translator::Diff::schema_diff(): Renamed column can't find old column "order.last_bill_date" for renamed column

The warning come when deploy/129/001-auto.yml file is accessed/analized

I do not understand why it says that last_bill_date can not be found. It is obvious why: for scheme 129 the column last_bill_date was renamed to billed_to.

last_bill_date was at 128 scheme and there is no such field at 129 scheme. DBIx::Class::Migration should not try to find last_bill_date for 129, to my mind

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

No branches or pull requests

1 participant