Sha256: 886e5747d7d7ae57cade968971f7be315e241771e7e92071a49f4df7c4815b4f

Contents?: true

Size: 1.99 KB

Versions: 2

Compression:

Stored size: 1.99 KB

Contents

class CreateAdminpanelTables < ActiveRecord::Migration
  def migrate(direction)
    super
    # Create a default user
    if direction == :up && Rails.env.development?
      role = Adminpanel::Role.new(:name => "Admin")
      role.save
      Adminpanel::User.new(:email => 'admin@admin.com', :name => "Admin", :password => 'password', :password_confirmation => 'password', :role_id => role.id).save
      puts "The password for admin@admin.com is: password"
    end
  end

  def change
    create_users
    create_roles
    create_permissions
    create_auths
    create_sections
    create_sectionfiles
  end

  private
  def create_users
    create_table :adminpanel_users do |t|
      t.string  :name
      t.string  :email
      t.integer :role_id
      t.string  :password_digest
      t.string  :remember_token
      t.timestamps
    end
    add_index :adminpanel_users, [:email]
    add_index :adminpanel_users, [:remember_token]
  end

  def create_sectionfiles
    create_table :adminpanel_sectionfiles do |t|
      t.string  :file
      t.integer :section_id
      t.timestamps
    end
  end

  def create_roles
    create_table :adminpanel_roles do |t|
      t.string :name
      t.timestamps
    end
  end

  def create_permissions
    create_table :adminpanel_permissions do |t|
        t.integer  :role_id
        t.integer  :action
        t.string   :resource
        t.timestamps
    end
  end

  def create_auths
    create_table :adminpanel_auths do |t|
      t.string   :name
      t.string   :key
      t.string   :value
      t.timestamps
    end
    add_index :adminpanel_auths, [:name]
    add_index :adminpanel_auths, [:key]
  end

  def create_sections
    create_table :adminpanel_sections do |t|
      t.string  :name
      t.boolean :has_description
      t.text    :description
      t.string  :key
      t.string  :page
      t.boolean :has_image
      t.integer :max_files, default: 0
      t.timestamps
    end
    add_index :adminpanel_sections, [:key]
    add_index :adminpanel_sections, [:page]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adminpanel-2.3.1 lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb
adminpanel-2.3.0 lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb