Skip to content

Downgrade script is wrong. Data was lost. #183

Description

@KES777

Upgrade is correct:

diff --git a/share/migrations/PostgreSQL/upgrade/4-5/001-auto.sql b/share/migrations/Post>
new file mode 100644
index 000000000..69d445035
--- /dev/null
+++ b/share/migrations/PostgreSQL/upgrade/4-5/001-auto.sql
@@ -0,0 +1,15 @@
+-- Convert schema '/home/kes/work/projects/bot/app/share/migrations/_source/deploy/4/001>
+
+;
+BEGIN;
+
+;
+ALTER TABLE "tracker" RENAME COLUMN "me_id" TO "tracker_user_xid";
+
+;
+ALTER TABLE "user" RENAME COLUMN "telegram_xid" TO "telegram_user_xid";
+
+;
+
+COMMIT;
+

For downgrade I also expect RENAME COLUMN but DROP is used, which cause data loss.

diff --git a/share/migrations/PostgreSQL/downgrade/5-4/001-auto.sql b/share/migrations/Po>
new file mode 100644
index 000000000..7ee5f5780
--- /dev/null
+++ b/share/migrations/PostgreSQL/downgrade/5-4/001-auto.sql
@@ -0,0 +1,21 @@
+-- Convert schema '/home/kes/work/projects/bot/app/share/migrations/_source/deploy/5/001>
+
+;
+BEGIN;
+
+;
+ALTER TABLE "tracker" DROP COLUMN "tracker_user_xid";
+
+;
+ALTER TABLE "tracker" ADD COLUMN "me_id" integer NOT NULL;
+
+;
+ALTER TABLE "user" DROP COLUMN "telegram_user_xid";
+
+;
+ALTER TABLE "user" ADD COLUMN "telegram_xid" integer NOT NULL;
+
+;
+
+COMMIT;
+

How to reproduce:

diff --git a/lib/Db/Result/Tracker.pm b/lib/Db/Result/Tracker.pm
index 7f082852a..3f933fbab 100644
--- a/lib/Db/Result/Tracker.pm
+++ b/lib/Db/Result/Tracker.pm
@@ -34,8 +34,11 @@ $X->add_columns(
         data_type =>  'text',
     },
     # User id at tracker
-    me_id =>  {
+    tracker_user_xid =>  {
         data_type =>  'int',
+        extra     =>  {
+            renamed_from => 'me_id',
+        },
     },
     options =>  {
         data_type        =>  'json',
diff --git a/lib/Db/Result/User.pm b/lib/Db/Result/User.pm
index a5b92e7bd..d5db08b08 100644
--- a/lib/Db/Result/User.pm
+++ b/lib/Db/Result/User.pm
@@ -22,8 +22,11 @@ $X->add_columns(
     passw =>  {
         data_type =>  'text',
     },
-    telegram_xid => {
+    telegram_user_xid => {
         data_type => 'int',
+        extra     =>  {
+            renamed_from => 'telegram_xid',
+        },
     },
 );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions