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

Fixes to Migrator provided by Maiha #201

Merged
merged 2 commits into from
May 12, 2018
Merged

Fixes to Migrator provided by Maiha #201

merged 2 commits into from
May 12, 2018

Conversation

drujensen
Copy link
Member

Dry up codes about creating tables in specs, and put it production code as Granite::ORM.migrator.
This helps users

  • to add tables in specs easily
  • to create tables in experiment and deployment
class User < Granite::ORM::Base
  adapter mysql
  field name : String
end

User.migrator.create
mysql> describe users;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| name  | varchar(255) | YES  |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+

implementation

  • mapping rules from crystal class to database type is defined in adapters.
    • Granite::Adapter::Base::Schema::Types
    • Granite::Adapter::Mysql::Schema::Types
    • ...

I just defined rules about basic classes used in current specs.

  • Bool, Float32, Float64, Int32, Int64, String, Time

If migrator is exected with undefined types, it raises a runtime error as below.

Migrator(Granite::Adapter::Mysql) doesn't support 'Time::Span' yet. (Exception)

Best regards,

@drujensen
Copy link
Member Author

This PR was approved earlier but after several changes to master, the data structure changed for CONTENT_TYPE.

@drujensen drujensen merged commit 6870dcf into master May 12, 2018
@drujensen drujensen deleted the migrator branch May 12, 2018 14:14
@faustinoaq
Copy link
Contributor

Interesting, @drujensen would be possible to use this for amber db migrate ?

I still have some issues trying to fix amberframework/micrate#31 😅

WDYT?

@drujensen
Copy link
Member Author

No. This doesn't handle migrations. For example, if you rename a field, you would need to migrate the data from one field to the other. micrate is better suited for this type of task.

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

Successfully merging this pull request may close these issues.

3 participants