Blob of db/migrate/014_create_articles.rb (raw blob data)

1
2 #
3 # This migration is numbered 407_ to allow space for Gitorious to grow without causing conflict,
4 # also it's 7 because there are 6 migrations before it on the project being merged in, the order
5 # of the migrations is importand for foreign_key_migrations plugin
6 #
7
8 class CreateArticles < ActiveRecord::Migration
9
10 def self.up
11
12 create_table :categories do |t|
13 t.string :name, :default => "Empty", :null => false
14 t.column :category_type, :enum, :limit => [:primary, :secondary], :default => :primary
15 t.string :slug #FIXME needs :null => false
16 t.integer :parent
17 t.timestamps
18 #foreign keys
19 t.integer :user_id, :on_delete => :cascade, :on_update => :cascade, :default => 1
20 end
21 add_index :categories, [:id]
22
23 create_table :articles do |t|
24 t.string :title, :default => "Empty", :null => false
25 t.text :body
26 t.text :body_summary
27 #also need to change the article_type table/fixtures
28 t.column :article_type, :enum, :limit => [:news, :code, :release, :howto, :issue, :other], :default => :other, :null => true
29 t.column :status, :enum, :limit => [:draft, :published, :test, :deleted], :default => :draft
30 t.column :comment_status, :enum, :limit => [:open, :closed, :users, :administrators], :default => :open
31 t.string :permalink, :null => false
32 t.column :audience, :enum, :limit => [:public, :members], :default => :public
33 t.integer :views, :default => 0
34 #t.boolean :members_only, :default => false, :null => false
35 t.timestamps
36 #foreign keys
37 t.integer :user_id, :on_delete => :cascade, :on_update => :cascade, :default => 1
38 t.integer :category_id, :on_delete => :cascade, :on_update => :cascade, :default => 1
39 #FIXME allow project|version|release polymorphic (maybe, it would help the project filter on the article tab)
40 t.integer :project_id, :on_delete => :cascade, :on_update => :cascade, :default => 1
41 end
42 add_index :articles, [:id]
43 add_index :articles, [:status, :audience]
44 add_index :articles, [:permalink]
45 add_index :articles, [:user_id]
46 add_index :articles, [:project_id]
47 add_index :articles, [:category_id]
48 add_index :articles, [:article_type]
49
50 #this is used for joins to improve performance of at least one query
51 create_table :article_types do |t|
52 t.column :article_type, :enum, :limit => [:news, :code, :release, :howto, :issue, :other], :default => :other, :null => true
53 t.string :name, :default => "" #FIXME possibly redundant
54 end
55 add_index :article_types, [:article_type]
56
57
58 end
59
60 def self.down
61 drop_table :article_types
62 drop_table :articles
63 drop_table :categories
64 end
65
66 end