Skip to content

Commit

Permalink
Add migrations to install generator
Browse files Browse the repository at this point in the history
  • Loading branch information
marjinal1st committed Jan 20, 2014
1 parent 0ac450a commit cf14c91
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/generators/kebapage/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require 'rails/generators/migration'
require 'rails/generators/active_record'

module Kebapress
module Kebapage
module Generators
class Kebapage::InstallGenerator < Rails::Generators::NamedBase
class Kebapage::InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
include Rails::Generators::Migration

Expand All @@ -18,6 +18,13 @@ def self.next_migration_number(dirname)
ActiveRecord::Generators::Base.next_migration_number(dirname)
end

def create_migration_file
migration_template 'migrations/static_pages.rb', 'db/migrate/create_kebapage_static_pages.rb' rescue nil
migration_template 'migrations/photos.rb', 'db/migrate/create_kebapage_photos.rb' rescue nil
migration_template 'migrations/add_slug_to_kebapage_static_pages.rb', 'db/migrate/add_slug_to_kebapage_static_pages.rb' rescue nil
migration_template 'migrations/friendly_id_slugs.rb', 'db/migrate/create_friendly_id_slugs.rb' rescue nil
end

def copy_locales
directory 'locales', 'config/locales'
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddSlugToKebapageStaticPages < ActiveRecord::Migration
def change
add_column :kebapage_static_pages, :slug, :string
add_index :kebapage_static_pages, :slug
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CreateFriendlyIdSlugs < ActiveRecord::Migration
def change
create_table :friendly_id_slugs do |t|
t.string :slug, :null => false
t.integer :sluggable_id, :null => false
t.string :sluggable_type, :limit => 50
t.string :scope
t.datetime :created_at
end
add_index :friendly_id_slugs, :sluggable_id
add_index :friendly_id_slugs, [:slug, :sluggable_type]
add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], :unique => true
add_index :friendly_id_slugs, :sluggable_type
end
end
10 changes: 10 additions & 0 deletions lib/generators/kebapage/install/templates/migrations/photos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateKebapagePhotos < ActiveRecord::Migration
def change
create_table :kebapage_photos do |t|
t.attachment :photo
t.references :static_page, index: true

t.timestamps
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateKebapageStaticPages < ActiveRecord::Migration
def change
create_table :kebapage_static_pages do |t|
t.string :title
t.text :content

t.timestamps
end
end
end

0 comments on commit cf14c91

Please sign in to comment.