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

Migration on MySQL: initial migration with VARCHAR type fails, despite having a max lenght #17

Closed
CrsiX opened this issue Nov 3, 2022 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@CrsiX
Copy link
Contributor

CrsiX commented Nov 3, 2022

Suppose the following initial migration:

[Migration]
Hash = '2856395125008994900'
Initial = true
Replaces = []

[[Migration.Operations]]
Type = 'CreateModel'
Name = 'user'

[[Migration.Operations.Fields]]
Name = 'id'
Type = 'int64'

[[Migration.Operations.Fields.Annotations]]
Type = 'auto_increment'

[[Migration.Operations.Fields.Annotations]]
Type = 'primary_key'

[[Migration.Operations.Fields]]
Name = 'username'
Type = 'varchar'

[[Migration.Operations.Fields.Annotations]]
Type = 'max_length'
Value = 255

[[Migration.Operations.Fields.Annotations]]
Type = 'not_null'

[[Migration.Operations.Fields]]
Name = 'age'
Type = 'int16'

[[Migration.Operations.Fields.Annotations]]
Type = 'not_null'

Then, applying it fails for a newly created, fresh database for rorm-cli migrate --database-config mysql.toml --log-sql:

CREATE TABLE IF NOT EXISTS _rorm__last_migration (id BIGINT(255) , updated_at DATETIME , migration_id INT(255) ); 
SELECT migration_id FROM _rorm__last_migration ORDER BY id DESC LIMIT 1;
Error: sql build error: VARCHAR must have a max_length annotation

The database only contains an empty _rorm_last_migration table afterwards:

MariaDB [db]> SHOW TABLES;
+-----------------------+
| Tables_in_db          |
+-----------------------+
| _rorm__last_migration |
+-----------------------+
1 row in set (0.000 sec)

MariaDB [db]> DESC _rorm__last_migration;
+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| id           | bigint(255) | YES  |     | NULL    |       |
| updated_at   | datetime    | YES  |     | NULL    |       |
| migration_id | int(255)    | YES  |     | NULL    |       |
+--------------+-------------+------+-----+---------+-------+
3 rows in set (0.010 sec)

MariaDB [db]> SELECT * FROM _rorm__last_migration;
Empty set (0.000 sec)
@myOmikron myOmikron self-assigned this Nov 5, 2022
@myOmikron myOmikron added the bug Something isn't working label Nov 5, 2022
@myOmikron
Copy link
Member

Good catch^^

@CrsiX
Copy link
Contributor Author

CrsiX commented Nov 5, 2022

This issue isn't fixed as of 8f9adbd. I can reproduce it with the same migration as above.

@CrsiX CrsiX reopened this Nov 5, 2022
@CrsiX
Copy link
Contributor Author

CrsiX commented Nov 5, 2022

This error is still present for the migration posted above and also for newly created migrations.

@CrsiX CrsiX reopened this Nov 5, 2022
@myOmikron
Copy link
Member

Can not reproduce

@CrsiX
Copy link
Contributor Author

CrsiX commented Nov 5, 2022

Has been fixed.

@CrsiX CrsiX closed this as completed Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants