0
0
Fork 0

add initial migration file and further adjustments

The 01_setup.rb contains the old table structure to make it possible to
migrate to the new system.
02_move_to_new on the other hand adjusts the old schema to the new
format and adds the full text function.

With that, the new schema is ready and the completion of the full text
search can continue.
This commit is contained in:
Gibheer 2014-02-03 23:43:46 +01:00
parent ee464a5c15
commit 3cac0daa68
2 changed files with 99 additions and 0 deletions

47
migrations/01_setup.rb Normal file
View File

@ -0,0 +1,47 @@
Sequel.migration do
change do
create_table(:accounts) do
primary_key :id
String :username, :size=>50
String :email, :size=>50
String :crypted_password, :size=>70
String :role, :size=>50
end
create_table(:tags) do
primary_key :id
String :name, :text=>true
end
create_table(:posts, :ignore_index_errors=>true) do
primary_key :id
String :title, :text=>true, :null=>false
DateTime :written
TrueClass :released, :default=>false
String :markup, :default=>"markdown", :text=>true
String :content, :text=>true
foreign_key :account_id, :accounts, :null=>false, :key=>[:id]
index [:account_id], :name=>:index_posts_account
index [:written, :id], :name=>:posts_written_id_idx
end
create_table(:comments, :ignore_index_errors=>true) do
primary_key :id
String :author, :size=>50
String :email, :size=>50
TrueClass :acknowledged, :default=>false
String :body, :text=>true
foreign_key :post_id, :posts, :null=>false, :key=>[:id]
index [:post_id], :name=>:index_comments_post
end
create_table(:post_tags) do
foreign_key :post_id, :posts, :null=>false, :key=>[:id]
foreign_key :tag_id, :tags, :null=>false, :key=>[:id]
primary_key [:post_id, :tag_id]
end
end
end

View File

@ -0,0 +1,52 @@
# this is the schema from the old platform
Sequel.migration do
up do
drop_table :post_tags
drop_table :comments
drop_table :tags
alter_table :posts do
add_column :language, String, :size => 10
end
from(:posts).update(:language => 'english')
alter_table :posts do
set_column_not_null :language
end
run 'create function search_field(posts) returns tsvector as $$' +
"select to_tsvector($1.language::regconfig, $1.title || ' ' || $1.content);" +
'$$ language sql immutable;'
end
down do
alter_table :posts do
drop_column :language
end
run 'drop function search_field(posts);'
create_table(:tags) do
primary_key :id
String :name, :text=>true
end
create_table(:comments, :ignore_index_errors=>true) do
primary_key :id
String :author, :size=>50
String :email, :size=>50
TrueClass :acknowledged, :default=>false
String :body, :text=>true
foreign_key :post_id, :posts, :null=>false, :key=>[:id]
index [:post_id], :name=>:index_comments_post
end
create_table(:post_tags) do
foreign_key :post_id, :posts, :null=>false, :key=>[:id]
foreign_key :tag_id, :tags, :null=>false, :key=>[:id]
primary_key [:post_id, :tag_id]
end
end
end