2020-08-07 01:14:14 +02:00
|
|
|
class CreateArticleMeta < ActiveRecord::Migration[4.2]
|
2009-01-06 11:49:19 +01:00
|
|
|
CATEGORY_SAMPLE = 'Sample Category'
|
|
|
|
TAX_STANDARD = 'Standard'
|
|
|
|
TAX_REDUCED = 'Reduced'
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
def self.up
|
|
|
|
# Add user roles...
|
2023-05-12 13:01:12 +02:00
|
|
|
add_column :groups, :role_article_meta, :boolean, default: false, null: false
|
2009-01-06 11:49:19 +01:00
|
|
|
Group.reset_column_information
|
|
|
|
puts "Give #{CreateGroups::GROUP_ADMIN} the role article_meta .."
|
2023-05-12 13:01:12 +02:00
|
|
|
raise 'Failed' unless Group.find_by_name(CreateGroups::GROUP_ADMIN).update_attribute(:role_article_meta, true)
|
2009-01-06 11:49:19 +01:00
|
|
|
raise 'Cannot find admin user!' unless admin = User.find_by_nick(CreateUsers::USER_ADMIN)
|
|
|
|
raise 'Failed to enable role_article_meta with admin user!' unless admin.role_article_meta?
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# ArticleCategories
|
|
|
|
create_table :article_categories do |t|
|
2023-05-12 13:01:12 +02:00
|
|
|
t.column :name, :string, null: false
|
2009-01-06 11:49:19 +01:00
|
|
|
t.column :description, :string
|
|
|
|
end
|
2023-05-12 13:01:12 +02:00
|
|
|
add_index(:article_categories, :name, unique: true)
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# Create sample category...
|
|
|
|
puts "Creating sample article category '#{CATEGORY_SAMPLE}'..."
|
2023-05-12 13:01:12 +02:00
|
|
|
ArticleCategory.create(name: CATEGORY_SAMPLE, description: 'This is just a sample article category.')
|
|
|
|
raise 'Failed!' unless category = ArticleCategory.find_by_name(CATEGORY_SAMPLE)
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.down
|
|
|
|
remove_column :groups, :role_article_meta
|
|
|
|
drop_table :article_categories
|
|
|
|
end
|
|
|
|
end
|