Sequel Migration Builder
Builds sequel migrations based on the differences between an abstract representation of the desired schema and a database instance.
This is quite a low-level library - it doesn’t provide any functionality to write out migration files, nor does it provide a ruby DSL for defining your schema (see Schema format below).
This library is also very, very new, so there WILL be bugs.
Install
sudo gem install sequel_migration_builder
Example
require 'sequel/migration_builder'
desired_schema = { ... } # see below
builder = Sequel::MigrationBuilder.new(DB)
migration_code = builder.generate_migration(desired_schema)
File.write("001_some_migration.rb", migration_code)
Schema format
The schema is an abstract representation of the tables in your database, as a hash. A sample YAML version might look like:
example_table:
primary_key: id
table_options:
engine: myisam
indexes:
foo_index_name:
columns: foo
unique: true
columns:
- name: id
column_type: integer
- name: foo
column_type: varchar
default: "bar"
null: true
size: 30
another_table:
...
Requirements
-
Sequel 3.20.0 or higher
TODO
-
Dropping tables when they are removed from the schema
-
Automigrate functionality
-
Dealing with renames in some way (even if just logging that they would be possible).
-
Changing table options with alter table
-
More database type parsers
Note on Patches/Pull Requests
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright
Copyright © 2010 Roland Swingler. See LICENSE for details.