rename database tables, columns

This commit is contained in:
zmagod 2017-01-24 16:07:22 +01:00
parent 53699193a2
commit 9624a17298
2 changed files with 100 additions and 65 deletions

View file

@ -0,0 +1,35 @@
class RenameOrganizationToTeam < ActiveRecord::Migration
def up
rename_table :organizations, :teams
rename_table :user_organizations, :user_teams
rename_column :custom_fields, :organization_id, :team_id
rename_column :logs, :organization_id, :team_id
rename_column :projects, :organization_id, :team_id
rename_column :protocol_keywords, :organization_id, :team_id
rename_column :protocols, :organization_id, :team_id
rename_column :sample_groups, :organization_id, :team_id
rename_column :sample_types, :organization_id, :team_id
rename_column :samples, :organization_id, :team_id
rename_column :samples_tables, :organization_id, :team_id
rename_column :user_teams, :organization_id, :team_id
rename_column :users, :current_organization_id, :current_team_id
end
def down
rename_table :teams, :organizations
rename_table :user_teams, :user_organizations
rename_column :custom_fields, :team_id, :organization_id
rename_column :logs, :team_id, :organization_id
rename_column :projects, :team_id, :organization_id
rename_column :protocol_keywords, :team_id, :organization_id
rename_column :protocols, :team_id, :organization_id
rename_column :sample_groups, :team_id, :organization_id
rename_column :sample_types, :team_id, :organization_id
rename_column :samples, :team_id, :organization_id
rename_column :samples_tables, :team_id, :organization_id
rename_column :user_organizations, :team_id, :organization_id
rename_column :users, :current_team_id, :current_organization_id
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170116143350) do
ActiveRecord::Schema.define(version: 20170124135736) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -111,14 +111,14 @@ ActiveRecord::Schema.define(version: 20170116143350) do
create_table "custom_fields", force: :cascade do |t|
t.string "name", null: false
t.integer "user_id", null: false
t.integer "organization_id", null: false
t.integer "team_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "last_modified_by_id"
end
add_index "custom_fields", ["last_modified_by_id"], name: "index_custom_fields_on_last_modified_by_id", using: :btree
add_index "custom_fields", ["organization_id"], name: "index_custom_fields_on_organization_id", using: :btree
add_index "custom_fields", ["team_id"], name: "index_custom_fields_on_team_id", using: :btree
add_index "custom_fields", ["user_id"], name: "index_custom_fields_on_user_id", using: :btree
create_table "delayed_jobs", force: :cascade do |t|
@ -165,8 +165,8 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_index "experiments", ["restored_by_id"], name: "index_experiments_on_restored_by_id", using: :btree
create_table "logs", force: :cascade do |t|
t.integer "organization_id", null: false
t.string "message", null: false
t.integer "team_id", null: false
t.string "message", null: false
end
create_table "my_module_comments", force: :cascade do |t|
@ -238,20 +238,6 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_index "notifications", ["created_at"], name: "index_notifications_on_created_at", using: :btree
create_table "organizations", force: :cascade do |t|
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "created_by_id"
t.integer "last_modified_by_id"
t.string "description"
t.integer "space_taken", limit: 8, default: 1048576, null: false
end
add_index "organizations", ["created_by_id"], name: "index_organizations_on_created_by_id", using: :btree
add_index "organizations", ["last_modified_by_id"], name: "index_organizations_on_last_modified_by_id", using: :btree
add_index "organizations", ["name"], name: "index_organizations_on_name", using: :btree
create_table "project_comments", force: :cascade do |t|
t.integer "project_id", null: false
t.integer "comment_id", null: false
@ -263,7 +249,7 @@ ActiveRecord::Schema.define(version: 20170116143350) do
t.string "name", null: false
t.integer "visibility", default: 0, null: false
t.datetime "due_date"
t.integer "organization_id", null: false
t.integer "team_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "archived", default: false, null: false
@ -279,19 +265,19 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_index "projects", ["created_by_id"], name: "index_projects_on_created_by_id", using: :btree
add_index "projects", ["last_modified_by_id"], name: "index_projects_on_last_modified_by_id", using: :btree
add_index "projects", ["name"], name: "index_projects_on_name", using: :gist
add_index "projects", ["organization_id"], name: "index_projects_on_organization_id", using: :btree
add_index "projects", ["restored_by_id"], name: "index_projects_on_restored_by_id", using: :btree
add_index "projects", ["team_id"], name: "index_projects_on_team_id", using: :btree
create_table "protocol_keywords", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "nr_of_protocols", default: 0
t.integer "organization_id", null: false
t.integer "team_id", null: false
end
add_index "protocol_keywords", ["name"], name: "index_protocol_keywords_on_name", using: :btree
add_index "protocol_keywords", ["organization_id"], name: "index_protocol_keywords_on_organization_id", using: :btree
add_index "protocol_keywords", ["team_id"], name: "index_protocol_keywords_on_team_id", using: :btree
create_table "protocol_protocol_keywords", force: :cascade do |t|
t.integer "protocol_id", null: false
@ -307,7 +293,7 @@ ActiveRecord::Schema.define(version: 20170116143350) do
t.text "description"
t.integer "added_by_id"
t.integer "my_module_id"
t.integer "organization_id", null: false
t.integer "team_id", null: false
t.integer "protocol_type", default: 0, null: false
t.integer "parent_id"
t.datetime "parent_updated_at"
@ -327,9 +313,9 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_index "protocols", ["description"], name: "index_protocols_on_description", using: :btree
add_index "protocols", ["my_module_id"], name: "index_protocols_on_my_module_id", using: :btree
add_index "protocols", ["name"], name: "index_protocols_on_name", using: :btree
add_index "protocols", ["organization_id"], name: "index_protocols_on_organization_id", using: :btree
add_index "protocols", ["parent_id"], name: "index_protocols_on_parent_id", using: :btree
add_index "protocols", ["restored_by_id"], name: "index_protocols_on_restored_by_id", using: :btree
add_index "protocols", ["team_id"], name: "index_protocols_on_team_id", using: :btree
create_table "report_elements", force: :cascade do |t|
t.integer "position", null: false
@ -445,7 +431,7 @@ ActiveRecord::Schema.define(version: 20170116143350) do
create_table "sample_groups", force: :cascade do |t|
t.string "name", null: false
t.string "color", default: "#ff0000", null: false
t.integer "organization_id", null: false
t.integer "team_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "created_by_id"
@ -454,7 +440,7 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_index "sample_groups", ["created_by_id"], name: "index_sample_groups_on_created_by_id", using: :btree
add_index "sample_groups", ["last_modified_by_id"], name: "index_sample_groups_on_last_modified_by_id", using: :btree
add_index "sample_groups", ["organization_id"], name: "index_sample_groups_on_organization_id", using: :btree
add_index "sample_groups", ["team_id"], name: "index_sample_groups_on_team_id", using: :btree
create_table "sample_my_modules", force: :cascade do |t|
t.integer "sample_id", null: false
@ -468,7 +454,7 @@ ActiveRecord::Schema.define(version: 20170116143350) do
create_table "sample_types", force: :cascade do |t|
t.string "name", null: false
t.integer "organization_id", null: false
t.integer "team_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "created_by_id"
@ -477,12 +463,12 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_index "sample_types", ["created_by_id"], name: "index_sample_types_on_created_by_id", using: :btree
add_index "sample_types", ["last_modified_by_id"], name: "index_sample_types_on_last_modified_by_id", using: :btree
add_index "sample_types", ["organization_id"], name: "index_sample_types_on_organization_id", using: :btree
add_index "sample_types", ["team_id"], name: "index_sample_types_on_team_id", using: :btree
create_table "samples", force: :cascade do |t|
t.string "name", null: false
t.integer "user_id", null: false
t.integer "organization_id", null: false
t.integer "team_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "sample_group_id"
@ -493,20 +479,20 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_index "samples", ["last_modified_by_id"], name: "index_samples_on_last_modified_by_id", using: :btree
add_index "samples", ["name"], name: "index_samples_on_name", using: :gist
add_index "samples", ["organization_id"], name: "index_samples_on_organization_id", using: :btree
add_index "samples", ["sample_group_id"], name: "index_samples_on_sample_group_id", using: :btree
add_index "samples", ["sample_type_id"], name: "index_samples_on_sample_type_id", using: :btree
add_index "samples", ["team_id"], name: "index_samples_on_team_id", using: :btree
add_index "samples", ["user_id"], name: "index_samples_on_user_id", using: :btree
create_table "samples_tables", force: :cascade do |t|
t.jsonb "status", default: {"time"=>0, "order"=>[[2, "desc"]], "start"=>0, "length"=>10, "search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "columns"=>[{"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}], "ColReorder"=>[0, 1, 2, 3, 4, 5, 6]}, null: false
t.integer "user_id", null: false
t.integer "organization_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.jsonb "status", default: {"time"=>0, "order"=>[[2, "desc"]], "start"=>0, "length"=>10, "search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "columns"=>[{"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}, {"search"=>{"regex"=>false, "smart"=>true, "search"=>"", "caseInsensitive"=>true}, "visible"=>true}], "ColReorder"=>[0, 1, 2, 3, 4, 5, 6]}, null: false
t.integer "user_id", null: false
t.integer "team_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "samples_tables", ["organization_id"], name: "index_samples_tables_on_organization_id", using: :btree
add_index "samples_tables", ["team_id"], name: "index_samples_tables_on_team_id", using: :btree
add_index "samples_tables", ["user_id"], name: "index_samples_tables_on_user_id", using: :btree
create_table "step_assets", force: :cascade do |t|
@ -580,6 +566,20 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_index "tags", ["name"], name: "index_tags_on_name", using: :gist
add_index "tags", ["project_id"], name: "index_tags_on_project_id", using: :btree
create_table "teams", force: :cascade do |t|
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "created_by_id"
t.integer "last_modified_by_id"
t.string "description"
t.integer "space_taken", limit: 8, default: 1048576, null: false
end
add_index "teams", ["created_by_id"], name: "index_teams_on_created_by_id", using: :btree
add_index "teams", ["last_modified_by_id"], name: "index_teams_on_last_modified_by_id", using: :btree
add_index "teams", ["name"], name: "index_teams_on_name", using: :btree
create_table "temp_files", force: :cascade do |t|
t.string "session_id", null: false
t.datetime "created_at", null: false
@ -614,19 +614,6 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_index "user_notifications", ["notification_id"], name: "index_user_notifications_on_notification_id", using: :btree
add_index "user_notifications", ["user_id"], name: "index_user_notifications_on_user_id", using: :btree
create_table "user_organizations", force: :cascade do |t|
t.integer "role", default: 1, null: false
t.integer "user_id", null: false
t.integer "organization_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "assigned_by_id"
end
add_index "user_organizations", ["assigned_by_id"], name: "index_user_organizations_on_assigned_by_id", using: :btree
add_index "user_organizations", ["organization_id"], name: "index_user_organizations_on_organization_id", using: :btree
add_index "user_organizations", ["user_id"], name: "index_user_organizations_on_user_id", using: :btree
create_table "user_projects", force: :cascade do |t|
t.integer "role", default: 0
t.integer "user_id", null: false
@ -640,6 +627,19 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_index "user_projects", ["project_id"], name: "index_user_projects_on_project_id", using: :btree
add_index "user_projects", ["user_id"], name: "index_user_projects_on_user_id", using: :btree
create_table "user_teams", force: :cascade do |t|
t.integer "role", default: 1, null: false
t.integer "user_id", null: false
t.integer "team_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "assigned_by_id"
end
add_index "user_teams", ["assigned_by_id"], name: "index_user_teams_on_assigned_by_id", using: :btree
add_index "user_teams", ["team_id"], name: "index_user_teams_on_team_id", using: :btree
add_index "user_teams", ["user_id"], name: "index_user_teams_on_user_id", using: :btree
create_table "users", force: :cascade do |t|
t.string "full_name", null: false
t.string "initials", null: false
@ -677,7 +677,7 @@ ActiveRecord::Schema.define(version: 20170116143350) do
t.boolean "recent_notification", default: true
t.boolean "assignments_notification_email", default: false
t.boolean "recent_notification_email", default: false
t.integer "current_organization_id"
t.integer "current_team_id"
t.boolean "system_message_notification_email", default: false
t.string "authentication_token", limit: 30
end
@ -707,14 +707,14 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_foreign_key "comments", "users", column: "last_modified_by_id"
add_foreign_key "connections", "my_modules", column: "input_id"
add_foreign_key "connections", "my_modules", column: "output_id"
add_foreign_key "custom_fields", "organizations"
add_foreign_key "custom_fields", "teams"
add_foreign_key "custom_fields", "users"
add_foreign_key "custom_fields", "users", column: "last_modified_by_id"
add_foreign_key "experiments", "users", column: "archived_by_id"
add_foreign_key "experiments", "users", column: "created_by_id"
add_foreign_key "experiments", "users", column: "last_modified_by_id"
add_foreign_key "experiments", "users", column: "restored_by_id"
add_foreign_key "logs", "organizations"
add_foreign_key "logs", "teams"
add_foreign_key "my_module_comments", "comments"
add_foreign_key "my_module_comments", "my_modules"
add_foreign_key "my_module_groups", "experiments"
@ -727,21 +727,19 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_foreign_key "my_modules", "users", column: "last_modified_by_id"
add_foreign_key "my_modules", "users", column: "restored_by_id"
add_foreign_key "notifications", "users", column: "generator_user_id"
add_foreign_key "organizations", "users", column: "created_by_id"
add_foreign_key "organizations", "users", column: "last_modified_by_id"
add_foreign_key "project_comments", "comments"
add_foreign_key "project_comments", "projects"
add_foreign_key "projects", "organizations"
add_foreign_key "projects", "teams"
add_foreign_key "projects", "users", column: "archived_by_id"
add_foreign_key "projects", "users", column: "created_by_id"
add_foreign_key "projects", "users", column: "last_modified_by_id"
add_foreign_key "projects", "users", column: "restored_by_id"
add_foreign_key "protocol_keywords", "organizations"
add_foreign_key "protocol_keywords", "teams"
add_foreign_key "protocol_protocol_keywords", "protocol_keywords"
add_foreign_key "protocol_protocol_keywords", "protocols"
add_foreign_key "protocols", "my_modules"
add_foreign_key "protocols", "organizations"
add_foreign_key "protocols", "protocols", column: "parent_id"
add_foreign_key "protocols", "teams"
add_foreign_key "protocols", "users", column: "added_by_id"
add_foreign_key "protocols", "users", column: "archived_by_id"
add_foreign_key "protocols", "users", column: "restored_by_id"
@ -773,18 +771,18 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_foreign_key "sample_comments", "samples"
add_foreign_key "sample_custom_fields", "custom_fields"
add_foreign_key "sample_custom_fields", "samples"
add_foreign_key "sample_groups", "organizations"
add_foreign_key "sample_groups", "teams"
add_foreign_key "sample_groups", "users", column: "created_by_id"
add_foreign_key "sample_groups", "users", column: "last_modified_by_id"
add_foreign_key "sample_my_modules", "my_modules"
add_foreign_key "sample_my_modules", "samples"
add_foreign_key "sample_my_modules", "users", column: "assigned_by_id"
add_foreign_key "sample_types", "organizations"
add_foreign_key "sample_types", "teams"
add_foreign_key "sample_types", "users", column: "created_by_id"
add_foreign_key "sample_types", "users", column: "last_modified_by_id"
add_foreign_key "samples", "organizations"
add_foreign_key "samples", "sample_groups"
add_foreign_key "samples", "sample_types"
add_foreign_key "samples", "teams"
add_foreign_key "samples", "users"
add_foreign_key "samples", "users", column: "last_modified_by_id"
add_foreign_key "step_assets", "assets"
@ -801,16 +799,18 @@ ActiveRecord::Schema.define(version: 20170116143350) do
add_foreign_key "tags", "projects"
add_foreign_key "tags", "users", column: "created_by_id"
add_foreign_key "tags", "users", column: "last_modified_by_id"
add_foreign_key "teams", "users", column: "created_by_id"
add_foreign_key "teams", "users", column: "last_modified_by_id"
add_foreign_key "user_my_modules", "my_modules"
add_foreign_key "user_my_modules", "users"
add_foreign_key "user_my_modules", "users", column: "assigned_by_id"
add_foreign_key "user_notifications", "notifications"
add_foreign_key "user_notifications", "users"
add_foreign_key "user_organizations", "organizations"
add_foreign_key "user_organizations", "users"
add_foreign_key "user_organizations", "users", column: "assigned_by_id"
add_foreign_key "user_projects", "projects"
add_foreign_key "user_projects", "users"
add_foreign_key "user_projects", "users", column: "assigned_by_id"
add_foreign_key "users", "organizations", column: "current_organization_id"
add_foreign_key "user_teams", "teams"
add_foreign_key "user_teams", "users"
add_foreign_key "user_teams", "users", column: "assigned_by_id"
add_foreign_key "users", "teams", column: "current_team_id"
end