Welcome Guest, Not a member yet? Register   Sign In
Migrating Migrations Table from CI3 for existing databases
#1

(This post was last modified: 02-02-2023, 02:01 PM by objecttothis. Edit Reason: tag error )

The documentation gives update instructions in step 9 to run the migration in development after dropping the existing table then exporting the table to production and import the data.  This works fine for new installs, but does nothing for people upgrading the WebApp from the previous version which was on CI3 to the new version which will be on CI4. What I (and I think anyone else converting an existing CI3 WebApp) need is a means to upgrade the CI3 migrations table to CI4 without losing the current migration version, since CI4 migrate re-running migrations that have already been run in a CI3 version of the webapp will likely break things.

I was able to generate the CI4 version of the table by renaming the CI3 table and running php spark migrateConfusedtatus.  From that I generated a script to modify the CI3 table to match the structure of the CI4 version.
Code:
ALTER TABLE `ospos_migrations`
MODIFY COLUMN `version` VARCHAR(255) NOT NULL,
ADD `id` bigint(20) UNSIGNED NOT NULL,
ADD `class` varchar(255) NOT NULL,
ADD `group` varchar(255) NOT NULL,
ADD `namespace` varchar(255) NOT NULL,
ADD `time` int(11) NOT NULL,
ADD `batch` int(11) UNSIGNED NOT NULL;

ALTER TABLE `ospos_migrations`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `ospos_migrations`
  MODIFY COLUMN `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

UPDATE `ospos_migrations`
SET
`namespace` = 'App',
`time` = 0,
`batch` = 0
WHERE `ospos_migrations`.`id` = 1

The problem is that if I run php spark migrateConfusedtatus again, it doesn't see the existing version

The above script leaves me with a single row containing:
version 20210714140000 (this is the second to last migration)
id 1
class NULL
group NULL
namespace App
time 0
batch 0

Code:
php spark migrate:status

CodeIgniter v4.3.1 Command Line Tool - Server Time: 2023-02-03 00:23:29 UTC+04:00

+-----------+----------------+------------------------------+-------+-------------+-------+
| Namespace | Version        | Filename                    | Group | Migrated On | Batch |
+-----------+----------------+------------------------------+-------+-------------+-------+
| App      | 20170501150000 | upgrade_to_3_1_1            | ---  | ---        | ---  |
| App      | 20170502221506 | sales_tax_data              | ---  | ---        | ---  |
| App      | 20180225100000 | 2_0                          | ---  | ---        | ---  |
| App      | 20180501100000 | 3_2_1                        | ---  | ---        | ---  |
| App      | 20181015100000 | attributes                  | ---  | ---        | ---  |
| App      | 20190111270000 | upgrade_to_3_3_0            | ---  | ---        | ---  |
| App      | 20190129212600 | indiagst                    | ---  | ---        | ---  |
| App      | 20190213210000 | indiagst1                    | ---  | ---        | ---  |
| App      | 20190220210000 | indiagst2                    | ---  | ---        | ---  |
| App      | 20190301124900 | decimal_attribute_type      | ---  | ---        | ---  |
| App      | 20190317102600 | add_iso_4217                | ---  | ---        | ---  |
| App      | 20190427100000 | paymenttracking              | ---  | ---        | ---  |
| App      | 20190502100000 | refundtracking              | ---  | ---        | ---  |
| App      | 20190612100000 | dbfix                        | ---  | ---        | ---  |
| App      | 20190615100000 | fix_attribute_datetime      | ---  | ---        | ---  |
| App      | 20190712150200 | fix_empty_reports            | ---  | ---        | ---  |
| App      | 20191008100000 | receipttaxindicator          | ---  | ---        | ---  |
| App      | 20191231100000 | paymentdatefix              | ---  | ---        | ---  |
| App      | 20200125100000 | saleschangeprice            | ---  | ---        | ---  |
| App      | 20200202000000 | taxamount                    | ---  | ---        | ---  |
| App      | 20200215100000 | taxgroupconstraint          | ---  | ---        | ---  |
| App      | 20200508000000 | image_upload_defaults        | ---  | ---        | ---  |
| App      | 20200819000000 | modify_attr_links_constraint | ---  | ---        | ---  |
| App      | 20201108100000 | cashrounding                | ---  | ---        | ---  |
| App      | 20201110000000 | add_item_kit_number          | ---  | ---        | ---  |
| App      | 20210103000000 | modify_session_datatype      | ---  | ---        | ---  |
| App      | 20210422000000 | database_optimizations      | ---  | ---        | ---  |
| App      | 20210422000001 | remove_duplicate_links      | ---  | ---        | ---  |
| App      | 20210714140000 | move_expenses_categories    | ---  | ---        | ---  |
| App      | 20220127000000 | convert_to_ci4              | ---  | ---        | ---  |
+-----------+----------------+------------------------------+-------+-------------+-------+

And of course it tries to run all the migrations when I run php spark migrate. CI3 migrations is much simpler, so I'm trying to figure out missing information. \App\Config\Migrations $timestampFormat is 'YmdHis_'
  • Do I need a row for each migration in the new table that has run?
  • What needs to be entered in class, group time and batch columns in order for CI4 migrations to pick up the migrations that have already run from CI3?
  • I think I need to manually run whatever script I generate to convert the migrations table when it detects that the installation still has a CI3 migrations table unless \MigrationRunner\force() with the migration file will actually work... I kinda doubt force() would work, because it's probably expecting a CI4 table. Is this assumption accurate?
Reply


Messages In This Thread
Migrating Migrations Table from CI3 for existing databases - by objecttothis - 02-02-2023, 01:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB