Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Create migrations with model generator #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/generators/sequel/model/model_generator.rb
Expand Up @@ -8,9 +8,15 @@ class ModelGenerator < Base

check_class_collision

class_option :migration, :type => :boolean
class_option :timestamps, :type => :boolean
class_option :parent, :type => :string, :desc => "The parent class for the generated model"

def create_migration_file
return unless options[:migration]
migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
end

def create_model_file
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
end
Expand Down
14 changes: 14 additions & 0 deletions lib/generators/sequel/model/templates/migration.rb
@@ -0,0 +1,14 @@
class <%= migration_file_name.camelize %>Migration < Sequel::Migration
def up
create_table :<%= table_name %> do
primary_key :id
<% attributes.each do |attribute| -%>
<%= attribute.type_class %> :<%= attribute.name %>
<% end -%>
end
end

def down
drop_table :<%= table_name %>
end
end