From 95dda89fc622911eeff37dab62e72a2bad799a55 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Thu, 3 Aug 2023 08:16:13 +0200 Subject: [PATCH] Updated migration script to update on down, and failsafe for papertype --- .../134_create_label_paper_types_table.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/application/migrations/134_create_label_paper_types_table.php b/application/migrations/134_create_label_paper_types_table.php index afc9c4ff..6159628e 100644 --- a/application/migrations/134_create_label_paper_types_table.php +++ b/application/migrations/134_create_label_paper_types_table.php @@ -64,6 +64,7 @@ class Migration_create_label_paper_types_table extends CI_Migration { $this->db->query("insert into paper_types (paper_id,user_id,paper_name,metric,width,orientation,height) values ('3','-1','letter','mm','215.900','P','279.400');"); $this->db->query("insert ignore paper_types (user_id,paper_name,metric,width,orientation,height) SELECT u.user_id, pt.paper_name, pt.metric, pt.width, pt.orientation,pt.height FROM paper_types pt inner join users u where pt.user_id = -1;"); $this->db->query("update label_types l set l.paper_type_id=(select p.paper_id from paper_types p where upper(p.paper_name)=upper(l.paper_type) and p.user_id=l.user_id limit 1) where l.paper_type_id=0;"); + $this->db->query("update label_types l set l.paper_type_id = (select p.paper_id from paper_types p where p.user_id = l.user_id limit 1) where l.paper_type_id = 0;"); $this->db->query("alter table label_types drop column paper_type;"); } @@ -73,5 +74,18 @@ class Migration_create_label_paper_types_table extends CI_Migration { if ($this->db->table_exists('paper_types')) { $this->dbforge->drop_table('paper_types'); } + + if ($this->db->field_exists('paper_type_id', 'label_types')) { + $this->dbforge->drop_column('label_types', 'paper_type_id'); + } + + if (!$this->db->field_exists('paper_type', 'label_types')) { + $fields = array( + 'paper_type varchar(250)', + ); + + $this->dbforge->add_column('label_types', $fields); + $this->db->query("update label_types set paper_type = 'a4';"); + } } }