Commit 5dbb5dd5 authored by hh1966's avatar hh1966
Browse files

Add migration from description to body for research_plans

parent bb9669f7
......@@ -4,7 +4,7 @@ class ResearchPlan < ActiveRecord::Base
include Collectable
include Taggable
serialize :description, Hash
serialize :body, Array
belongs_to :creator, foreign_key: :created_by, class_name: 'User'
validates :creator, :name, presence: true
......
class AddBodyToResearchPlans < ActiveRecord::Migration
class ResearchPlan < ActiveRecord::Base
serialize :description, Hash
serialize :body, Array
end
def up
add_column :research_plans, :body, :text
ResearchPlan.find_each do |rp|
body = [
{
"id" => SecureRandom.uuid,
"type" => "ketcher",
"value" => {
"sdf_file" => rp.sdf_file,
"svg_file" => rp.svg_file,
"thumb_svg" => rp.thumb_svg
}
},
{
"id" => SecureRandom.uuid,
"type" => "richtext",
"value" => rp.description
}
]
rp.update_column(:body, body)
end
remove_column :research_plans, :description
remove_column :research_plans, :sdf_file
remove_column :research_plans, :svg_file
remove_column :research_plans, :thumb_svg
ResearchPlan.reset_column_information
end
def down
add_column :research_plans, :thumb_svg, :string
add_column :research_plans, :svg_file, :string
add_column :research_plans, :sdf_file, :string
add_column :research_plans, :description, :text
ResearchPlan.find_each do |rp|
rp.update_column(:thumb_svg, rp.body[0]["value"]["thumb_svg"])
rp.update_column(:svg_file, rp.body[0]["value"]["svg_file"])
rp.update_column(:sdf_file, rp.body[0]["value"]["sdf_file"])
rp.update_column(:description, rp.body[1]["value"])
end
remove_column :research_plans, :body
ResearchPlan.reset_column_information
end
end
......@@ -11,12 +11,12 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190712090136) do
ActiveRecord::Schema.define(version: 20190716092051) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "pg_trgm"
enable_extension "hstore"
enable_extension "pg_trgm"
enable_extension "uuid-ossp"
create_table "affiliations", force: :cascade do |t|
......@@ -78,8 +78,8 @@ ActiveRecord::Schema.define(version: 20190712090136) do
t.string "token", null: false
t.integer "user_id"
t.inet "ip"
t.string "fqdn"
t.string "role"
t.string "fqdn"
t.datetime "created_at"
t.datetime "updated_at"
end
......@@ -477,7 +477,7 @@ ActiveRecord::Schema.define(version: 20190712090136) do
add_index "molecules", ["deleted_at"], name: "index_molecules_on_deleted_at", using: :btree
add_index "molecules", ["inchikey", "is_partial"], name: "index_molecules_on_inchikey_and_is_partial", unique: true, using: :btree
create_table "notifications", force: :cascade do |t|
create_table "notifications", force: :cascade do |t|
t.integer "message_id"
t.integer "user_id"
t.integer "is_ack", default: 0
......@@ -624,15 +624,12 @@ ActiveRecord::Schema.define(version: 20190712090136) do
add_index "reports_users", ["user_id"], name: "index_reports_users_on_user_id", using: :btree
create_table "research_plans", force: :cascade do |t|
t.string "name", null: false
t.text "description"
t.string "sdf_file"
t.string "svg_file"
t.integer "created_by", null: false
t.string "name", null: false
t.integer "created_by", null: false
t.datetime "deleted_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "thumb_svg"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "body"
end
create_table "residues", force: :cascade do |t|
......@@ -680,7 +677,6 @@ ActiveRecord::Schema.define(version: 20190712090136) do
t.integer "molecule_name_id"
t.string "molfile_version", limit: 20
t.jsonb "stereo"
t.string "mol_rdkit"
end
add_index "samples", ["deleted_at"], name: "index_samples_on_deleted_at", using: :btree
......@@ -772,18 +768,18 @@ ActiveRecord::Schema.define(version: 20190712090136) do
t.datetime "deleted_at"
t.hstore "counters", default: {"samples"=>"0", "reactions"=>"0", "wellplates"=>"0"}, null: false
t.string "name_abbreviation", limit: 5
t.boolean "is_templates_moderator", default: false, null: false
t.string "type", default: "Person"
t.string "reaction_name_prefix", limit: 3, default: "R"
t.hstore "layout", default: {"sample"=>"1", "screen"=>"4", "reaction"=>"2", "wellplate"=>"3", "research_plan"=>"5"}, null: false
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.hstore "layout", default: {"sample"=>"1", "screen"=>"4", "reaction"=>"2", "wellplate"=>"3", "research_plan"=>"5"}, null: false
t.integer "selected_device_id"
t.integer "failed_attempts", default: 0, null: false
t.string "unlock_token"
t.datetime "locked_at"
t.boolean "is_templates_moderator"
end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
......@@ -847,48 +843,48 @@ ActiveRecord::Schema.define(version: 20190712090136) do
RETURNS json
LANGUAGE sql
AS $function$
select array_to_json(array_agg(row_to_json(result))) from (
SELECT sync_collections_users.id, users.type,users.first_name || chr(32) || users.last_name as name,sync_collections_users.permission_level,
sync_collections_users.reaction_detail_level,sync_collections_users.sample_detail_level,sync_collections_users.screen_detail_level,sync_collections_users.wellplate_detail_level
FROM sync_collections_users
INNER JOIN users ON users.id = sync_collections_users.user_id AND users.deleted_at IS NULL
WHERE sync_collections_users.shared_by_id = $1 and sync_collections_users.collection_id = $2
group by sync_collections_users.id,users.type,users.name_abbreviation,users.first_name,users.last_name,sync_collections_users.permission_level
) as result
$function$
select array_to_json(array_agg(row_to_json(result))) from (
SELECT sync_collections_users.id, users.type,users.first_name || chr(32) || users.last_name as name,sync_collections_users.permission_level,
sync_collections_users.reaction_detail_level,sync_collections_users.sample_detail_level,sync_collections_users.screen_detail_level,sync_collections_users.wellplate_detail_level
FROM sync_collections_users
INNER JOIN users ON users.id = sync_collections_users.user_id AND users.deleted_at IS NULL
WHERE sync_collections_users.shared_by_id = $1 and sync_collections_users.collection_id = $2
group by sync_collections_users.id,users.type,users.name_abbreviation,users.first_name,users.last_name,sync_collections_users.permission_level
) as result
$function$
SQL
create_function :detail_level_for_sample, sql_definition: <<-SQL
CREATE OR REPLACE FUNCTION public.detail_level_for_sample(in_user_id integer, in_sample_id integer)
RETURNS TABLE(detail_level_sample integer, detail_level_wellplate integer)
LANGUAGE plpgsql
AS $function$
declare
i_detail_level_wellplate integer default 0;
i_detail_level_sample integer default 0;
begin
select max(all_cols.sample_detail_level), max(all_cols.wellplate_detail_level)
into i_detail_level_sample, i_detail_level_wellplate
from
(
select v_sams_cols.cols_sample_detail_level sample_detail_level, v_sams_cols.cols_wellplate_detail_level wellplate_detail_level
from v_samples_collections v_sams_cols
where v_sams_cols.sams_id = in_sample_id
and v_sams_cols.cols_user_id in (select user_ids(in_user_id))
union
select sync_cols.sample_detail_level sample_detail_level, sync_cols.wellplate_detail_level wellplate_detail_level
from sync_collections_users sync_cols
inner join collections cols on cols.id = sync_cols.collection_id and cols.deleted_at is null
where sync_cols.collection_id in
(
select v_sams_cols.cols_id
from v_samples_collections v_sams_cols
where v_sams_cols.sams_id = in_sample_id
)
and sync_cols.user_id in (select user_ids(in_user_id))
) all_cols;
return query select coalesce(i_detail_level_sample,0) detail_level_sample, coalesce(i_detail_level_wellplate,0) detail_level_wellplate;
end;$function$
declare
i_detail_level_wellplate integer default 0;
i_detail_level_sample integer default 0;
begin
select max(all_cols.sample_detail_level), max(all_cols.wellplate_detail_level)
into i_detail_level_sample, i_detail_level_wellplate
from
(
select v_sams_cols.cols_sample_detail_level sample_detail_level, v_sams_cols.cols_wellplate_detail_level wellplate_detail_level
from v_samples_collections v_sams_cols
where v_sams_cols.sams_id = in_sample_id
and v_sams_cols.cols_user_id in (select user_ids(in_user_id))
union
select sync_cols.sample_detail_level sample_detail_level, sync_cols.wellplate_detail_level wellplate_detail_level
from sync_collections_users sync_cols
inner join collections cols on cols.id = sync_cols.collection_id and cols.deleted_at is null
where sync_cols.collection_id in
(
select v_sams_cols.cols_id
from v_samples_collections v_sams_cols
where v_sams_cols.sams_id = in_sample_id
)
and sync_cols.user_id in (select user_ids(in_user_id))
) all_cols;
return query select coalesce(i_detail_level_sample,0) detail_level_sample, coalesce(i_detail_level_wellplate,0) detail_level_wellplate;
end;$function$
SQL
create_function :generate_notifications, sql_definition: <<-SQL
CREATE OR REPLACE FUNCTION public.generate_notifications(in_channel_id integer, in_message_id integer, in_user_id integer, in_user_ids integer[])
......@@ -936,53 +932,53 @@ ActiveRecord::Schema.define(version: 20190712090136) do
RETURNS json
LANGUAGE plpgsql
AS $function$
begin
if (in_user_id = in_current_user_id) then
return null;
else
return (select row_to_json(result) from (
select users.id, users.name_abbreviation as initials ,users.type,users.first_name || chr(32) || users.last_name as name
from users where id = $1
) as result);
end if;
end;
$function$
begin
if (in_user_id = in_current_user_id) then
return null;
else
return (select row_to_json(result) from (
select users.id, users.name_abbreviation as initials ,users.type,users.first_name || chr(32) || users.last_name as name
from users where id = $1
) as result);
end if;
end;
$function$
SQL
create_function :user_as_json, sql_definition: <<-SQL
CREATE OR REPLACE FUNCTION public.user_as_json(user_id integer)
RETURNS json
LANGUAGE sql
AS $function$
select row_to_json(result) from (
select users.id, users.name_abbreviation as initials ,users.type,users.first_name || chr(32) || users.last_name as name
from users where id = $1
) as result
$function$
select row_to_json(result) from (
select users.id, users.name_abbreviation as initials ,users.type,users.first_name || chr(32) || users.last_name as name
from users where id = $1
) as result
$function$
SQL
create_function :user_ids, sql_definition: <<-SQL
CREATE OR REPLACE FUNCTION public.user_ids(user_id integer)
RETURNS TABLE(user_ids integer)
LANGUAGE sql
AS $function$
select $1 as id
union
(select users.id from users inner join users_groups ON users.id = users_groups.group_id WHERE users.deleted_at IS null
and users.type in ('Group') and users_groups.user_id = $1)
$function$
select $1 as id
union
(select users.id from users inner join users_groups ON users.id = users_groups.group_id WHERE users.deleted_at IS null
and users.type in ('Group') and users_groups.user_id = $1)
$function$
SQL
create_function :user_instrument, sql_definition: <<-SQL
CREATE OR REPLACE FUNCTION public.user_instrument(user_id integer, sc text)
RETURNS TABLE(instrument text)
LANGUAGE sql
AS $function$
select distinct extended_metadata -> 'instrument' as instrument from containers c
where c.container_type='dataset' and c.id in
(select ch.descendant_id from containers sc,container_hierarchies ch, samples s, users u
where sc.containable_type in ('Sample','Reaction') and ch.ancestor_id=sc.id and sc.containable_id=s.id
and s.created_by = u.id and u.id = $1 and ch.generations=3 group by descendant_id)
and upper(extended_metadata -> 'instrument') like upper($2 || '%')
order by extended_metadata -> 'instrument' limit 10
$function$
select distinct extended_metadata -> 'instrument' as instrument from containers c
where c.container_type='dataset' and c.id in
(select ch.descendant_id from containers sc,container_hierarchies ch, samples s, users u
where sc.containable_type in ('Sample','Reaction') and ch.ancestor_id=sc.id and sc.containable_id=s.id
and s.created_by = u.id and u.id = $1 and ch.generations=3 group by descendant_id)
and upper(extended_metadata -> 'instrument') like upper($2 || '%')
order by extended_metadata -> 'instrument' limit 10
$function$
SQL
create_view "literal_groups", sql_definition: <<-SQL
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment