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

baking migration, column default value #552

Closed
1 task done
Rakasch opened this issue May 9, 2022 · 0 comments · Fixed by #557
Closed
1 task done

baking migration, column default value #552

Rakasch opened this issue May 9, 2022 · 0 comments · Fixed by #557
Labels

Comments

@Rakasch
Copy link

Rakasch commented May 9, 2022

This is a :

  • bug

  • CakePHP Version: 4.3.8

  • Migrations plugin version: 3.5.1

  • Bake plugin version (if relevant): 2.7.0

  • Database server: 10.3.22-MariaDB-0+deb10u1

  • PHP Version: 8.0.13

  • Platform / OS: Debian

What you did

Created a migration file

bin/cake bake migration_snapshot Initial

The relevant table:

CREATE TABLE `mod_ti_tiles` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`theme_id` INT(11) UNSIGNED NOT NULL,
	`typ` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0',
	`width` SMALLINT(6) NOT NULL DEFAULT '0',
	`height` SMALLINT(6) NOT NULL DEFAULT '0',
	`kachel` LONGTEXT NOT NULL DEFAULT '{}' COLLATE 'utf8mb4_general_ci',
	`order` TINYINT(4) UNSIGNED NOT NULL COMMENT 'starting at 0',
	PRIMARY KEY (`id`) USING BTREE,
	INDEX `theme_id` (`theme_id`) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;

The table column 'kachel' of type LONGTEXT contains data in json format.
Therefore it has a default value of '{}'.

Actual Behavior

The code the migrator created for this column:

 ->addColumn('kachel', 'text', [
        'default' => '\'{}\'',
        'limit' => 4294967295,
        'null' => false,
    ])

If I run my tests with this migration file, it also inserts the quotes into the db value.
And of course the json is broken.

I dont know if it's relevant, so I'll mention it:
My database config has 'quoteIdentifiers' => true,

Expected Behavior

I changed the migration file manually to:

 ->addColumn('kachel', 'text', [
                'default' => '{}',
                'limit' => 4294967295,
                'null' => false,
            ])

Now my tests are running fine again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants