From 3d22a5404dde4e9ae67ce8cd3a79b06b742155f8 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 26 Oct 2017 16:59:00 +0200 Subject: [PATCH] add scenic gem, teams datatables sql view --- Gemfile | 1 + Gemfile.lock | 4 + .../client_api/teams/teams_controller.rb | 3 +- app/models/datatables/datatables_team.rb | 12 + app/models/user.rb | 1 + .../client_api/teams/index.json.jbuilder | 15 +- .../20171026090804_create_datatables_teams.rb | 5 + db/schema.rb | 1261 ++++++++--------- db/views/datatables_teams_v01.sql | 13 + spec/factories/my_module_groups.rb | 1 - spec/models/datatables/teams_spec.rb | 22 + spec/models/my_module_group_spec.rb | 3 - spec/spec_helper.rb | 1 + 13 files changed, 693 insertions(+), 649 deletions(-) create mode 100644 app/models/datatables/datatables_team.rb create mode 100644 db/migrate/20171026090804_create_datatables_teams.rb create mode 100644 db/views/datatables_teams_v01.sql create mode 100644 spec/models/datatables/teams_spec.rb diff --git a/Gemfile b/Gemfile index 85ecc1e71..dd8756746 100644 --- a/Gemfile +++ b/Gemfile @@ -66,6 +66,7 @@ gem 'delayed_paperclip', gem 'rubyzip' gem 'jbuilder' # JSON structures via a Builder-style DSL gem 'activerecord-import' +gem 'scenic', '~> 1.4' gem 'paperclip', '~> 5.1' # File attachment, image attachment library gem 'aws-sdk', '~> 2' diff --git a/Gemfile.lock b/Gemfile.lock index dcd6bd846..bfc9e85da 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -415,6 +415,9 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + scenic (1.4.0) + activerecord (>= 4.0.0) + railties (>= 4.0.0) scss_lint (0.55.0) rake (>= 0.9, < 13) sass (~> 3.4.20) @@ -562,6 +565,7 @@ DEPENDENCIES rubyzip sanitize (~> 4.4) sass-rails (~> 5.0.6) + scenic (~> 1.4) scss_lint sdoc (~> 0.4.0) selenium-webdriver diff --git a/app/controllers/client_api/teams/teams_controller.rb b/app/controllers/client_api/teams/teams_controller.rb index 9d3fdfc02..d19e2bb9d 100644 --- a/app/controllers/client_api/teams/teams_controller.rb +++ b/app/controllers/client_api/teams/teams_controller.rb @@ -4,8 +4,9 @@ module ClientApi include ClientApi::Users::UserTeamsHelper def index + teams = current_user.datatables_teams success_response(template: '/client_api/teams/index', - locals: { teams: current_user.teams_data }) + locals: { teams: teams }) end def create diff --git a/app/models/datatables/datatables_team.rb b/app/models/datatables/datatables_team.rb new file mode 100644 index 000000000..58739af9d --- /dev/null +++ b/app/models/datatables/datatables_team.rb @@ -0,0 +1,12 @@ +module Datatables + class DatatablesTeam < ApplicationRecord + belongs_to :user + private + + # this isn't strictly necessary, but it will prevent + # rails from calling save, which would fail anyway. + def readonly? + true + end + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 9cf7543df..a71afc1a2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -198,6 +198,7 @@ class User < ApplicationRecord has_many :user_notifications, inverse_of: :user has_many :notifications, through: :user_notifications has_many :zip_exports, inverse_of: :user, dependent: :destroy + has_many :datatables_teams, class_name: '::Datatables::DatatablesTeam' # If other errors besides parameter "avatar" exist, # they will propagate to "avatar" also, so remove them diff --git a/app/views/client_api/teams/index.json.jbuilder b/app/views/client_api/teams/index.json.jbuilder index f6958099d..245b1acb4 100644 --- a/app/views/client_api/teams/index.json.jbuilder +++ b/app/views/client_api/teams/index.json.jbuilder @@ -1,11 +1,10 @@ json.teams do - json.collection teams do |team| - json.id team.fetch('id') - json.name team.fetch('name') - json.members team.fetch('members') - json.role retrive_role_name(team.fetch('role') { nil }) - json.current_team team.fetch('current_team') - json.can_be_leaved team.fetch('can_be_leaved') - json.user_team_id team.fetch('user_team_id') + json.array teams do |team| + json.id team.id + json.name team.name + json.members team.members + json.role retrive_role_name(team.role) + json.can_be_leaved team.can_be_leaved + json.user_team_id team.user_team_id end end diff --git a/db/migrate/20171026090804_create_datatables_teams.rb b/db/migrate/20171026090804_create_datatables_teams.rb new file mode 100644 index 000000000..1aa9b0f19 --- /dev/null +++ b/db/migrate/20171026090804_create_datatables_teams.rb @@ -0,0 +1,5 @@ +class CreateDatatablesTeams < ActiveRecord::Migration[5.0] + def change + create_view :datatables_teams + end +end diff --git a/db/schema.rb b/db/schema.rb index 6046e0877..27ee1c37b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,802 +10,774 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170515141252) do +ActiveRecord::Schema.define(version: 20171026090804) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "pg_trgm" enable_extension "btree_gist" - create_table "activities", force: :cascade do |t| - t.integer "my_module_id" - t.integer "user_id" - t.integer "type_of", null: false - t.string "message", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "project_id", null: false - t.integer "experiment_id" + create_table "activities", id: :serial, force: :cascade do |t| + t.integer "my_module_id" + t.integer "user_id" + t.integer "type_of", null: false + t.string "message", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "project_id", null: false + t.integer "experiment_id" + t.index ["created_at"], name: "index_activities_on_created_at" + t.index ["experiment_id"], name: "index_activities_on_experiment_id" + t.index ["my_module_id"], name: "index_activities_on_my_module_id" + t.index ["project_id"], name: "index_activities_on_project_id" + t.index ["type_of"], name: "index_activities_on_type_of" + t.index ["user_id"], name: "index_activities_on_user_id" end - add_index "activities", ["created_at"], name: "index_activities_on_created_at", using: :btree - add_index "activities", ["experiment_id"], name: "index_activities_on_experiment_id", using: :btree - add_index "activities", ["my_module_id"], name: "index_activities_on_my_module_id", using: :btree - add_index "activities", ["project_id"], name: "index_activities_on_project_id", using: :btree - add_index "activities", ["type_of"], name: "index_activities_on_type_of", using: :btree - add_index "activities", ["user_id"], name: "index_activities_on_user_id", using: :btree - - create_table "asset_text_data", force: :cascade do |t| - t.text "data", null: false - t.integer "asset_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "asset_text_data", id: :serial, force: :cascade do |t| + t.text "data", null: false + t.integer "asset_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.tsvector "data_vector" + t.index ["asset_id"], name: "index_asset_text_data_on_asset_id", unique: true + t.index ["data_vector"], name: "index_asset_text_data_on_data_vector", using: :gin end - add_index "asset_text_data", ["asset_id"], name: "index_asset_text_data_on_asset_id", unique: true, using: :btree - add_index "asset_text_data", ["data_vector"], name: "index_asset_text_data_on_data_vector", using: :gin - - create_table "assets", force: :cascade do |t| - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "file_file_name" - t.string "file_content_type" - t.integer "file_file_size" + create_table "assets", id: :serial, force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "file_file_name" + t.string "file_content_type" + t.integer "file_file_size" t.datetime "file_updated_at" - t.integer "created_by_id" - t.integer "last_modified_by_id" - t.integer "estimated_size", default: 0, null: false - t.boolean "file_present", default: false, null: false - t.string "lock", limit: 1024 - t.integer "lock_ttl" - t.integer "version", default: 1 - t.boolean "file_processing" - t.integer "team_id" + t.integer "created_by_id" + t.integer "last_modified_by_id" + t.integer "estimated_size", default: 0, null: false + t.boolean "file_present", default: false, null: false + t.string "lock", limit: 1024 + t.integer "lock_ttl" + t.integer "version", default: 1 + t.boolean "file_processing" + t.integer "team_id" + t.index "trim_html_tags((file_file_name)::text) gin_trgm_ops", name: "index_assets_on_file_file_name", using: :gin + t.index ["created_at"], name: "index_assets_on_created_at" + t.index ["created_by_id"], name: "index_assets_on_created_by_id" + t.index ["last_modified_by_id"], name: "index_assets_on_last_modified_by_id" + t.index ["team_id"], name: "index_assets_on_team_id" end - add_index "assets", ["created_at"], name: "index_assets_on_created_at", using: :btree - add_index "assets", ["created_by_id"], name: "index_assets_on_created_by_id", using: :btree - add_index "assets", ["last_modified_by_id"], name: "index_assets_on_last_modified_by_id", using: :btree - add_index "assets", ["team_id"], name: "index_assets_on_team_id", using: :btree - - create_table "checklist_items", force: :cascade do |t| - t.string "text", null: false - t.boolean "checked", default: false, null: false - t.integer "checklist_id", 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.integer "position" + create_table "checklist_items", id: :serial, force: :cascade do |t| + t.string "text", null: false + t.boolean "checked", default: false, null: false + t.integer "checklist_id", 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.integer "position" + t.index "trim_html_tags((text)::text) gin_trgm_ops", name: "index_checklist_items_on_text", using: :gin + t.index ["checklist_id"], name: "index_checklist_items_on_checklist_id" + t.index ["created_by_id"], name: "index_checklist_items_on_created_by_id" + t.index ["last_modified_by_id"], name: "index_checklist_items_on_last_modified_by_id" end - add_index "checklist_items", ["checklist_id"], name: "index_checklist_items_on_checklist_id", using: :btree - add_index "checklist_items", ["created_by_id"], name: "index_checklist_items_on_created_by_id", using: :btree - add_index "checklist_items", ["last_modified_by_id"], name: "index_checklist_items_on_last_modified_by_id", using: :btree - - create_table "checklists", force: :cascade do |t| - t.string "name", null: false - t.integer "step_id", 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" + create_table "checklists", id: :serial, force: :cascade do |t| + t.string "name", null: false + t.integer "step_id", 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.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_checklists_on_name", using: :gin + t.index ["created_by_id"], name: "index_checklists_on_created_by_id" + t.index ["last_modified_by_id"], name: "index_checklists_on_last_modified_by_id" + t.index ["step_id"], name: "index_checklists_on_step_id" end - add_index "checklists", ["created_by_id"], name: "index_checklists_on_created_by_id", using: :btree - add_index "checklists", ["last_modified_by_id"], name: "index_checklists_on_last_modified_by_id", using: :btree - add_index "checklists", ["step_id"], name: "index_checklists_on_step_id", using: :btree - - create_table "comments", force: :cascade do |t| - t.string "message", null: false - t.integer "user_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "last_modified_by_id" - t.string "type" - t.integer "associated_id" + create_table "comments", id: :serial, force: :cascade do |t| + t.string "message", null: false + t.integer "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "last_modified_by_id" + t.string "type" + t.integer "associated_id" + t.index "trim_html_tags((message)::text) gin_trgm_ops", name: "index_comments_on_message", using: :gin + t.index ["associated_id"], name: "index_comments_on_associated_id" + t.index ["created_at"], name: "index_comments_on_created_at" + t.index ["last_modified_by_id"], name: "index_comments_on_last_modified_by_id" + t.index ["type"], name: "index_comments_on_type" + t.index ["user_id"], name: "index_comments_on_user_id" end - add_index "comments", ["associated_id"], name: "index_comments_on_associated_id", using: :btree - add_index "comments", ["created_at"], name: "index_comments_on_created_at", using: :btree - add_index "comments", ["last_modified_by_id"], name: "index_comments_on_last_modified_by_id", using: :btree - add_index "comments", ["type"], name: "index_comments_on_type", using: :btree - add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree - - create_table "connections", force: :cascade do |t| - t.integer "input_id", null: false + create_table "connections", id: :serial, force: :cascade do |t| + t.integer "input_id", null: false t.integer "output_id", null: false + t.index ["input_id"], name: "index_connections_on_input_id" + t.index ["output_id"], name: "index_connections_on_output_id" end - create_table "custom_fields", force: :cascade do |t| - t.string "name", 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 "last_modified_by_id" + create_table "custom_fields", id: :serial, force: :cascade do |t| + t.string "name", 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 "last_modified_by_id" + t.index ["last_modified_by_id"], name: "index_custom_fields_on_last_modified_by_id" + t.index ["team_id"], name: "index_custom_fields_on_team_id" + t.index ["user_id"], name: "index_custom_fields_on_user_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", ["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| - t.integer "priority", default: 0, null: false - t.integer "attempts", default: 0, null: false - t.text "handler", null: false - t.text "last_error" + create_table "delayed_jobs", id: :serial, force: :cascade do |t| + t.integer "priority", default: 0, null: false + t.integer "attempts", default: 0, null: false + t.text "handler", null: false + t.text "last_error" t.datetime "run_at" t.datetime "locked_at" t.datetime "failed_at" - t.string "locked_by" - t.string "queue" + t.string "locked_by" + t.string "queue" t.datetime "created_at" t.datetime "updated_at" + t.index ["priority", "run_at"], name: "delayed_jobs_priority" + t.index ["queue"], name: "delayed_jobs_queue" end - add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree - add_index "delayed_jobs", ["queue"], name: "delayed_jobs_queue", using: :btree - - create_table "experiments", force: :cascade do |t| - t.string "name", null: false - t.text "description" - t.integer "project_id", null: false - t.integer "created_by_id", null: false - t.integer "last_modified_by_id", null: false - t.boolean "archived", default: false, null: false - t.integer "archived_by_id" + create_table "experiments", id: :serial, force: :cascade do |t| + t.string "name", null: false + t.text "description" + t.integer "project_id", null: false + t.integer "created_by_id", null: false + t.integer "last_modified_by_id", null: false + t.boolean "archived", default: false, null: false + t.integer "archived_by_id" t.datetime "archived_on" - t.integer "restored_by_id" + t.integer "restored_by_id" t.datetime "restored_on" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "workflowimg_file_name" - t.string "workflowimg_content_type" - t.integer "workflowimg_file_size" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "workflowimg_file_name" + t.string "workflowimg_content_type" + t.integer "workflowimg_file_size" t.datetime "workflowimg_updated_at" + t.index ["archived_by_id"], name: "index_experiments_on_archived_by_id" + t.index ["created_by_id"], name: "index_experiments_on_created_by_id" + t.index ["last_modified_by_id"], name: "index_experiments_on_last_modified_by_id" + t.index ["name"], name: "index_experiments_on_name" + t.index ["project_id"], name: "index_experiments_on_project_id" + t.index ["restored_by_id"], name: "index_experiments_on_restored_by_id" end - add_index "experiments", ["archived_by_id"], name: "index_experiments_on_archived_by_id", using: :btree - add_index "experiments", ["created_by_id"], name: "index_experiments_on_created_by_id", using: :btree - add_index "experiments", ["last_modified_by_id"], name: "index_experiments_on_last_modified_by_id", using: :btree - add_index "experiments", ["name"], name: "index_experiments_on_name", using: :btree - add_index "experiments", ["project_id"], name: "index_experiments_on_project_id", using: :btree - add_index "experiments", ["restored_by_id"], name: "index_experiments_on_restored_by_id", using: :btree - - create_table "my_module_groups", 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 "experiment_id", default: 0, null: false + create_table "my_module_groups", id: :serial, force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "created_by_id" + t.integer "experiment_id", default: 0, null: false + t.index ["created_by_id"], name: "index_my_module_groups_on_created_by_id" + t.index ["experiment_id"], name: "index_my_module_groups_on_experiment_id" end - add_index "my_module_groups", ["created_by_id"], name: "index_my_module_groups_on_created_by_id", using: :btree - add_index "my_module_groups", ["experiment_id"], name: "index_my_module_groups_on_experiment_id", using: :btree - - create_table "my_module_repository_rows", force: :cascade do |t| - t.integer "repository_row_id", null: false - t.integer "my_module_id" - t.integer "assigned_by_id", null: false + create_table "my_module_repository_rows", id: :serial, force: :cascade do |t| + t.integer "repository_row_id", null: false + t.integer "my_module_id" + t.integer "assigned_by_id", null: false t.datetime "created_at" t.datetime "updated_at" + t.index ["my_module_id", "repository_row_id"], name: "index_my_module_ids_repository_row_ids" + t.index ["repository_row_id"], name: "index_my_module_repository_rows_on_repository_row_id" end - add_index "my_module_repository_rows", ["my_module_id", "repository_row_id"], name: "index_my_module_ids_repository_row_ids", using: :btree - add_index "my_module_repository_rows", ["repository_row_id"], name: "index_my_module_repository_rows_on_repository_row_id", using: :btree - - create_table "my_module_tags", force: :cascade do |t| + create_table "my_module_tags", id: :serial, force: :cascade do |t| t.integer "my_module_id" t.integer "tag_id" t.integer "created_by_id" + t.index ["created_by_id"], name: "index_my_module_tags_on_created_by_id" + t.index ["my_module_id"], name: "index_my_module_tags_on_my_module_id" + t.index ["tag_id"], name: "index_my_module_tags_on_tag_id" end - add_index "my_module_tags", ["created_by_id"], name: "index_my_module_tags_on_created_by_id", using: :btree - add_index "my_module_tags", ["my_module_id"], name: "index_my_module_tags_on_my_module_id", using: :btree - add_index "my_module_tags", ["tag_id"], name: "index_my_module_tags_on_tag_id", using: :btree - - create_table "my_modules", force: :cascade do |t| - t.string "name", null: false + create_table "my_modules", id: :serial, force: :cascade do |t| + t.string "name", null: false t.datetime "due_date" - t.string "description" - t.integer "x", default: 0, null: false - t.integer "y", default: 0, null: false - t.integer "my_module_group_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "archived", default: false, null: false + t.string "description" + t.integer "x", default: 0, null: false + t.integer "y", default: 0, null: false + t.integer "my_module_group_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "archived", default: false, null: false t.datetime "archived_on" - t.integer "created_by_id" - t.integer "last_modified_by_id" - t.integer "archived_by_id" - t.integer "restored_by_id" + t.integer "created_by_id" + t.integer "last_modified_by_id" + t.integer "archived_by_id" + t.integer "restored_by_id" t.datetime "restored_on" - t.integer "nr_of_assigned_samples", default: 0 - t.integer "workflow_order", default: -1, null: false - t.integer "experiment_id", default: 0, null: false - t.integer "state", limit: 2, default: 0 + t.integer "nr_of_assigned_samples", default: 0 + t.integer "workflow_order", default: -1, null: false + t.integer "experiment_id", default: 0, null: false + t.integer "state", limit: 2, default: 0 t.datetime "completed_on" + t.index "trim_html_tags((description)::text) gin_trgm_ops", name: "index_my_modules_on_description", using: :gin + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_my_modules_on_name", using: :gin + t.index ["archived_by_id"], name: "index_my_modules_on_archived_by_id" + t.index ["created_by_id"], name: "index_my_modules_on_created_by_id" + t.index ["experiment_id"], name: "index_my_modules_on_experiment_id" + t.index ["last_modified_by_id"], name: "index_my_modules_on_last_modified_by_id" + t.index ["my_module_group_id"], name: "index_my_modules_on_my_module_group_id" + t.index ["restored_by_id"], name: "index_my_modules_on_restored_by_id" end - add_index "my_modules", ["archived_by_id"], name: "index_my_modules_on_archived_by_id", using: :btree - add_index "my_modules", ["created_by_id"], name: "index_my_modules_on_created_by_id", using: :btree - add_index "my_modules", ["experiment_id"], name: "index_my_modules_on_experiment_id", using: :btree - add_index "my_modules", ["last_modified_by_id"], name: "index_my_modules_on_last_modified_by_id", using: :btree - add_index "my_modules", ["my_module_group_id"], name: "index_my_modules_on_my_module_group_id", using: :btree - add_index "my_modules", ["restored_by_id"], name: "index_my_modules_on_restored_by_id", using: :btree - - create_table "notifications", force: :cascade do |t| - t.string "title" - t.string "message" - t.integer "type_of", null: false - t.integer "generator_user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "notifications", id: :serial, force: :cascade do |t| + t.string "title" + t.string "message" + t.integer "type_of", null: false + t.integer "generator_user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["created_at"], name: "index_notifications_on_created_at" end - add_index "notifications", ["created_at"], name: "index_notifications_on_created_at", using: :btree - - create_table "projects", force: :cascade do |t| - t.string "name", null: false - t.integer "visibility", default: 0, null: false + create_table "projects", id: :serial, force: :cascade do |t| + t.string "name", null: false + t.integer "visibility", default: 0, null: false t.datetime "due_date" - 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 + 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 t.datetime "archived_on" - t.integer "created_by_id" - t.integer "last_modified_by_id" - t.integer "archived_by_id" - t.integer "restored_by_id" + t.integer "created_by_id" + t.integer "last_modified_by_id" + t.integer "archived_by_id" + t.integer "restored_by_id" t.datetime "restored_on" - t.string "experiments_order" + t.string "experiments_order" + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_projects_on_name", using: :gin + t.index ["archived_by_id"], name: "index_projects_on_archived_by_id" + t.index ["created_by_id"], name: "index_projects_on_created_by_id" + t.index ["last_modified_by_id"], name: "index_projects_on_last_modified_by_id" + t.index ["restored_by_id"], name: "index_projects_on_restored_by_id" + t.index ["team_id"], name: "index_projects_on_team_id" end - add_index "projects", ["archived_by_id"], name: "index_projects_on_archived_by_id", using: :btree - 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", ["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 "team_id", null: false + create_table "protocol_keywords", id: :serial, 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 "team_id", null: false + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_protocol_keywords_on_name", using: :gin + t.index ["team_id"], name: "index_protocol_keywords_on_team_id" end - 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 + create_table "protocol_protocol_keywords", id: :serial, force: :cascade do |t| + t.integer "protocol_id", null: false t.integer "protocol_keyword_id", null: false + t.index ["protocol_id"], name: "index_protocol_protocol_keywords_on_protocol_id" + t.index ["protocol_keyword_id"], name: "index_protocol_protocol_keywords_on_protocol_keyword_id" end - add_index "protocol_protocol_keywords", ["protocol_id"], name: "index_protocol_protocol_keywords_on_protocol_id", using: :btree - add_index "protocol_protocol_keywords", ["protocol_keyword_id"], name: "index_protocol_protocol_keywords_on_protocol_keyword_id", using: :btree - - create_table "protocols", force: :cascade do |t| - t.string "name" - t.text "authors" - t.text "description" - t.integer "added_by_id" - t.integer "my_module_id" - t.integer "team_id", null: false - t.integer "protocol_type", default: 0, null: false - t.integer "parent_id" + create_table "protocols", id: :serial, force: :cascade do |t| + t.string "name" + t.text "authors" + t.text "description" + t.integer "added_by_id" + t.integer "my_module_id" + t.integer "team_id", null: false + t.integer "protocol_type", default: 0, null: false + t.integer "parent_id" t.datetime "parent_updated_at" - t.integer "archived_by_id" + t.integer "archived_by_id" t.datetime "archived_on" - t.integer "restored_by_id" + t.integer "restored_by_id" t.datetime "restored_on" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.datetime "published_on" - t.integer "nr_of_linked_children", default: 0 + t.integer "nr_of_linked_children", default: 0 + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_protocols_on_name", using: :gin + t.index "trim_html_tags(authors) gin_trgm_ops", name: "index_protocols_on_authors", using: :gin + t.index "trim_html_tags(description) gin_trgm_ops", name: "index_protocols_on_description", using: :gin + t.index ["added_by_id"], name: "index_protocols_on_added_by_id" + t.index ["archived_by_id"], name: "index_protocols_on_archived_by_id" + t.index ["my_module_id"], name: "index_protocols_on_my_module_id" + t.index ["parent_id"], name: "index_protocols_on_parent_id" + t.index ["protocol_type"], name: "index_protocols_on_protocol_type" + t.index ["restored_by_id"], name: "index_protocols_on_restored_by_id" + t.index ["team_id"], name: "index_protocols_on_team_id" end - add_index "protocols", ["added_by_id"], name: "index_protocols_on_added_by_id", using: :btree - add_index "protocols", ["archived_by_id"], name: "index_protocols_on_archived_by_id", using: :btree - add_index "protocols", ["my_module_id"], name: "index_protocols_on_my_module_id", using: :btree - add_index "protocols", ["parent_id"], name: "index_protocols_on_parent_id", using: :btree - add_index "protocols", ["protocol_type"], name: "index_protocols_on_protocol_type", 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 - t.integer "type_of", null: false - t.integer "sort_order", default: 0 - t.integer "report_id" - t.integer "parent_id" - t.integer "project_id" - t.integer "my_module_id" - t.integer "step_id" - t.integer "result_id" - t.integer "checklist_id" - t.integer "asset_id" - t.integer "table_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "experiment_id" - t.integer "repository_id" + create_table "report_elements", id: :serial, force: :cascade do |t| + t.integer "position", null: false + t.integer "type_of", null: false + t.integer "sort_order", default: 0 + t.integer "report_id" + t.integer "parent_id" + t.integer "project_id" + t.integer "my_module_id" + t.integer "step_id" + t.integer "result_id" + t.integer "checklist_id" + t.integer "asset_id" + t.integer "table_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "experiment_id" + t.integer "repository_id" + t.index ["asset_id"], name: "index_report_elements_on_asset_id" + t.index ["checklist_id"], name: "index_report_elements_on_checklist_id" + t.index ["experiment_id"], name: "index_report_elements_on_experiment_id" + t.index ["my_module_id"], name: "index_report_elements_on_my_module_id" + t.index ["parent_id"], name: "index_report_elements_on_parent_id" + t.index ["project_id"], name: "index_report_elements_on_project_id" + t.index ["report_id"], name: "index_report_elements_on_report_id" + t.index ["repository_id"], name: "index_report_elements_on_repository_id" + t.index ["result_id"], name: "index_report_elements_on_result_id" + t.index ["step_id"], name: "index_report_elements_on_step_id" + t.index ["table_id"], name: "index_report_elements_on_table_id" end - add_index "report_elements", ["asset_id"], name: "index_report_elements_on_asset_id", using: :btree - add_index "report_elements", ["checklist_id"], name: "index_report_elements_on_checklist_id", using: :btree - add_index "report_elements", ["experiment_id"], name: "index_report_elements_on_experiment_id", using: :btree - add_index "report_elements", ["my_module_id"], name: "index_report_elements_on_my_module_id", using: :btree - add_index "report_elements", ["parent_id"], name: "index_report_elements_on_parent_id", using: :btree - add_index "report_elements", ["project_id"], name: "index_report_elements_on_project_id", using: :btree - add_index "report_elements", ["report_id"], name: "index_report_elements_on_report_id", using: :btree - add_index "report_elements", ["repository_id"], name: "index_report_elements_on_repository_id", using: :btree - add_index "report_elements", ["result_id"], name: "index_report_elements_on_result_id", using: :btree - add_index "report_elements", ["step_id"], name: "index_report_elements_on_step_id", using: :btree - add_index "report_elements", ["table_id"], name: "index_report_elements_on_table_id", using: :btree - - create_table "reports", force: :cascade do |t| - t.string "name", null: false - t.string "description" - t.integer "project_id", null: false - t.integer "user_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "last_modified_by_id" + create_table "reports", id: :serial, force: :cascade do |t| + t.string "name", null: false + t.string "description" + t.integer "project_id", null: false + t.integer "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "last_modified_by_id" + t.index "trim_html_tags((description)::text) gin_trgm_ops", name: "index_reports_on_description", using: :gin + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_reports_on_name", using: :gin + t.index ["last_modified_by_id"], name: "index_reports_on_last_modified_by_id" + t.index ["project_id"], name: "index_reports_on_project_id" + t.index ["user_id"], name: "index_reports_on_user_id" end - add_index "reports", ["last_modified_by_id"], name: "index_reports_on_last_modified_by_id", using: :btree - add_index "reports", ["project_id"], name: "index_reports_on_project_id", using: :btree - add_index "reports", ["user_id"], name: "index_reports_on_user_id", using: :btree - - create_table "repositories", force: :cascade do |t| - t.integer "team_id" - t.integer "created_by_id", null: false - t.string "name" + create_table "repositories", id: :serial, force: :cascade do |t| + t.integer "team_id" + t.integer "created_by_id", null: false + t.string "name" t.datetime "created_at" t.datetime "updated_at" + t.index ["team_id"], name: "index_repositories_on_team_id" end - add_index "repositories", ["team_id"], name: "index_repositories_on_team_id", using: :btree - - create_table "repository_cells", force: :cascade do |t| - t.integer "repository_row_id" - t.integer "repository_column_id" - t.integer "value_id" - t.string "value_type" + create_table "repository_cells", id: :serial, force: :cascade do |t| + t.integer "repository_row_id" + t.integer "repository_column_id" + t.string "value_type" + t.integer "value_id" t.datetime "created_at" t.datetime "updated_at" + t.index ["repository_column_id"], name: "index_repository_cells_on_repository_column_id" + t.index ["repository_row_id"], name: "index_repository_cells_on_repository_row_id" + t.index ["value_type", "value_id"], name: "index_repository_cells_on_value_type_and_value_id" end - add_index "repository_cells", ["repository_column_id"], name: "index_repository_cells_on_repository_column_id", using: :btree - add_index "repository_cells", ["repository_row_id"], name: "index_repository_cells_on_repository_row_id", using: :btree - add_index "repository_cells", ["value_type", "value_id"], name: "index_repository_cells_on_value_type_and_value_id", using: :btree - - create_table "repository_columns", force: :cascade do |t| - t.integer "repository_id" - t.integer "created_by_id", null: false - t.string "name" - t.integer "data_type", null: false + create_table "repository_columns", id: :serial, force: :cascade do |t| + t.integer "repository_id" + t.integer "created_by_id", null: false + t.string "name" + t.integer "data_type", null: false t.datetime "created_at" t.datetime "updated_at" + t.index ["repository_id"], name: "index_repository_columns_on_repository_id" end - add_index "repository_columns", ["repository_id"], name: "index_repository_columns_on_repository_id", using: :btree - - create_table "repository_date_values", force: :cascade do |t| + create_table "repository_date_values", id: :serial, force: :cascade do |t| t.datetime "data" t.datetime "created_at" t.datetime "updated_at" - t.integer "created_by_id", null: false - t.integer "last_modified_by_id", null: false + t.integer "created_by_id", null: false + t.integer "last_modified_by_id", null: false end - create_table "repository_rows", force: :cascade do |t| - t.integer "repository_id" - t.integer "created_by_id", null: false - t.integer "last_modified_by_id", null: false - t.string "name" + create_table "repository_rows", id: :serial, force: :cascade do |t| + t.integer "repository_id" + t.integer "created_by_id", null: false + t.integer "last_modified_by_id", null: false + t.string "name" t.datetime "created_at" t.datetime "updated_at" + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_repository_rows_on_name", using: :gin + t.index ["repository_id"], name: "index_repository_rows_on_repository_id" end - add_index "repository_rows", ["name"], name: "index_repository_rows_on_name", using: :btree - add_index "repository_rows", ["repository_id"], name: "index_repository_rows_on_repository_id", using: :btree - - create_table "repository_table_states", force: :cascade do |t| - t.jsonb "state", null: false - t.integer "user_id", null: false - t.integer "repository_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "repository_table_states", id: :serial, force: :cascade do |t| + t.jsonb "state", null: false + t.integer "user_id", null: false + t.integer "repository_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["repository_id"], name: "index_repository_table_states_on_repository_id" + t.index ["user_id"], name: "index_repository_table_states_on_user_id" end - add_index "repository_table_states", ["repository_id"], name: "index_repository_table_states_on_repository_id", using: :btree - add_index "repository_table_states", ["user_id"], name: "index_repository_table_states_on_user_id", using: :btree - - create_table "repository_text_values", force: :cascade do |t| - t.string "data" + create_table "repository_text_values", id: :serial, force: :cascade do |t| + t.string "data" t.datetime "created_at" t.datetime "updated_at" - t.integer "created_by_id", null: false - t.integer "last_modified_by_id", null: false + t.integer "created_by_id", null: false + t.integer "last_modified_by_id", null: false + t.index "trim_html_tags((data)::text) gin_trgm_ops", name: "index_repository_text_values_on_data", using: :gin end - create_table "result_assets", force: :cascade do |t| + create_table "result_assets", id: :serial, force: :cascade do |t| t.integer "result_id", null: false - t.integer "asset_id", null: false - end - - add_index "result_assets", ["result_id", "asset_id"], name: "index_result_assets_on_result_id_and_asset_id", using: :btree - - create_table "result_tables", force: :cascade do |t| - t.integer "result_id", null: false - t.integer "table_id", null: false - end - - add_index "result_tables", ["result_id", "table_id"], name: "index_result_tables_on_result_id_and_table_id", using: :btree - - create_table "result_texts", force: :cascade do |t| - t.string "text", null: false - t.integer "result_id", null: false - end - - add_index "result_texts", ["result_id"], name: "index_result_texts_on_result_id", using: :btree - - create_table "results", force: :cascade do |t| - t.string "name" - t.integer "my_module_id", null: false - t.integer "user_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "archived", default: false, null: false - t.datetime "archived_on" - t.integer "last_modified_by_id" - t.integer "archived_by_id" - t.integer "restored_by_id" - t.datetime "restored_on" - end - - add_index "results", ["archived_by_id"], name: "index_results_on_archived_by_id", using: :btree - add_index "results", ["created_at"], name: "index_results_on_created_at", using: :btree - add_index "results", ["last_modified_by_id"], name: "index_results_on_last_modified_by_id", using: :btree - add_index "results", ["my_module_id"], name: "index_results_on_my_module_id", using: :btree - add_index "results", ["restored_by_id"], name: "index_results_on_restored_by_id", using: :btree - add_index "results", ["user_id"], name: "index_results_on_user_id", using: :btree - - create_table "sample_custom_fields", force: :cascade do |t| - t.string "value", null: false - t.integer "custom_field_id", null: false - t.integer "sample_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - add_index "sample_custom_fields", ["custom_field_id"], name: "index_sample_custom_fields_on_custom_field_id", using: :btree - add_index "sample_custom_fields", ["sample_id"], name: "index_sample_custom_fields_on_sample_id", using: :btree - - create_table "sample_groups", force: :cascade do |t| - t.string "name", null: false - t.string "color", default: "#ff0000", 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" - t.integer "last_modified_by_id" - end - - 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", ["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 - t.integer "my_module_id", null: false - t.integer "assigned_by_id" - t.datetime "assigned_on" - end - - add_index "sample_my_modules", ["assigned_by_id"], name: "index_sample_my_modules_on_assigned_by_id", using: :btree - add_index "sample_my_modules", ["sample_id", "my_module_id"], name: "index_sample_my_modules_on_sample_id_and_my_module_id", using: :btree - - create_table "sample_types", force: :cascade do |t| - t.string "name", 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" - t.integer "last_modified_by_id" - end - - 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", ["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 "team_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "sample_group_id" - t.integer "sample_type_id" - t.integer "last_modified_by_id" - t.integer "nr_of_modules_assigned_to", default: 0 - end - - add_index "samples", ["last_modified_by_id"], name: "index_samples_on_last_modified_by_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 "team_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - 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 "settings", force: :cascade do |t| - t.text "type", null: false - t.jsonb "values", default: {}, null: false - end - - add_index "settings", ["type"], name: "index_settings_on_type", unique: true, using: :btree - - create_table "step_assets", force: :cascade do |t| - t.integer "step_id", null: false t.integer "asset_id", null: false + t.index ["result_id", "asset_id"], name: "index_result_assets_on_result_id_and_asset_id" end - add_index "step_assets", ["step_id", "asset_id"], name: "index_step_assets_on_step_id_and_asset_id", using: :btree - - create_table "step_tables", force: :cascade do |t| - t.integer "step_id", null: false + create_table "result_tables", id: :serial, force: :cascade do |t| + t.integer "result_id", null: false t.integer "table_id", null: false + t.index ["result_id", "table_id"], name: "index_result_tables_on_result_id_and_table_id" end - add_index "step_tables", ["step_id", "table_id"], name: "index_step_tables_on_step_id_and_table_id", unique: true, using: :btree + create_table "result_texts", id: :serial, force: :cascade do |t| + t.string "text", null: false + t.integer "result_id", null: false + t.index "trim_html_tags((text)::text) gin_trgm_ops", name: "index_result_texts_on_text", using: :gin + t.index ["result_id"], name: "index_result_texts_on_result_id" + end - create_table "steps", force: :cascade do |t| - t.string "name" - t.string "description" - t.integer "position", null: false - t.boolean "completed", null: false + create_table "results", id: :serial, force: :cascade do |t| + t.string "name" + t.integer "my_module_id", null: false + t.integer "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "archived", default: false, null: false + t.datetime "archived_on" + t.integer "last_modified_by_id" + t.integer "archived_by_id" + t.integer "restored_by_id" + t.datetime "restored_on" + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_results_on_name", using: :gin + t.index ["archived_by_id"], name: "index_results_on_archived_by_id" + t.index ["created_at"], name: "index_results_on_created_at" + t.index ["last_modified_by_id"], name: "index_results_on_last_modified_by_id" + t.index ["my_module_id"], name: "index_results_on_my_module_id" + t.index ["restored_by_id"], name: "index_results_on_restored_by_id" + t.index ["user_id"], name: "index_results_on_user_id" + end + + create_table "sample_custom_fields", id: :serial, force: :cascade do |t| + t.string "value", null: false + t.integer "custom_field_id", null: false + t.integer "sample_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index "trim_html_tags((value)::text) gin_trgm_ops", name: "index_sample_custom_fields_on_value", using: :gin + t.index ["custom_field_id"], name: "index_sample_custom_fields_on_custom_field_id" + t.index ["sample_id"], name: "index_sample_custom_fields_on_sample_id" + end + + create_table "sample_groups", id: :serial, force: :cascade do |t| + t.string "name", null: false + t.string "color", default: "#ff0000", 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" + t.integer "last_modified_by_id" + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_sample_groups_on_name", using: :gin + t.index ["created_by_id"], name: "index_sample_groups_on_created_by_id" + t.index ["last_modified_by_id"], name: "index_sample_groups_on_last_modified_by_id" + t.index ["team_id"], name: "index_sample_groups_on_team_id" + end + + create_table "sample_my_modules", id: :serial, force: :cascade do |t| + t.integer "sample_id", null: false + t.integer "my_module_id", null: false + t.integer "assigned_by_id" + t.datetime "assigned_on" + t.index ["assigned_by_id"], name: "index_sample_my_modules_on_assigned_by_id" + t.index ["my_module_id"], name: "index_sample_my_modules_on_my_module_id" + t.index ["sample_id", "my_module_id"], name: "index_sample_my_modules_on_sample_id_and_my_module_id" + end + + create_table "sample_types", id: :serial, force: :cascade do |t| + t.string "name", 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" + t.integer "last_modified_by_id" + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_sample_types_on_name", using: :gin + t.index ["created_by_id"], name: "index_sample_types_on_created_by_id" + t.index ["last_modified_by_id"], name: "index_sample_types_on_last_modified_by_id" + t.index ["team_id"], name: "index_sample_types_on_team_id" + end + + create_table "samples", id: :serial, force: :cascade do |t| + t.string "name", 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 "sample_group_id" + t.integer "sample_type_id" + t.integer "last_modified_by_id" + t.integer "nr_of_modules_assigned_to", default: 0 + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_samples_on_name", using: :gin + t.index ["last_modified_by_id"], name: "index_samples_on_last_modified_by_id" + t.index ["sample_group_id"], name: "index_samples_on_sample_group_id" + t.index ["sample_type_id"], name: "index_samples_on_sample_type_id" + t.index ["team_id"], name: "index_samples_on_team_id" + t.index ["user_id"], name: "index_samples_on_user_id" + end + + create_table "samples_tables", id: :serial, 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}], "assigned"=>"all", "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 + t.index ["team_id"], name: "index_samples_tables_on_team_id" + t.index ["user_id"], name: "index_samples_tables_on_user_id" + end + + create_table "settings", id: :serial, force: :cascade do |t| + t.text "type", null: false + t.jsonb "values", default: {}, null: false + t.index ["type"], name: "index_settings_on_type", unique: true + end + + create_table "step_assets", id: :serial, force: :cascade do |t| + t.integer "step_id", null: false + t.integer "asset_id", null: false + t.index ["step_id", "asset_id"], name: "index_step_assets_on_step_id_and_asset_id" + end + + create_table "step_tables", id: :serial, force: :cascade do |t| + t.integer "step_id", null: false + t.integer "table_id", null: false + t.index ["step_id", "table_id"], name: "index_step_tables_on_step_id_and_table_id", unique: true + end + + create_table "steps", id: :serial, force: :cascade do |t| + t.string "name" + t.string "description" + t.integer "position", null: false + t.boolean "completed", null: false t.datetime "completed_on" - t.integer "user_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "last_modified_by_id" - t.integer "protocol_id", null: false + t.integer "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "last_modified_by_id" + t.integer "protocol_id", null: false + t.index "trim_html_tags((description)::text) gin_trgm_ops", name: "index_steps_on_description", using: :gin + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_steps_on_name", using: :gin + t.index ["created_at"], name: "index_steps_on_created_at" + t.index ["last_modified_by_id"], name: "index_steps_on_last_modified_by_id" + t.index ["position"], name: "index_steps_on_position" + t.index ["protocol_id"], name: "index_steps_on_protocol_id" + t.index ["user_id"], name: "index_steps_on_user_id" end - add_index "steps", ["created_at"], name: "index_steps_on_created_at", using: :btree - add_index "steps", ["last_modified_by_id"], name: "index_steps_on_last_modified_by_id", using: :btree - add_index "steps", ["position"], name: "index_steps_on_position", using: :btree - add_index "steps", ["protocol_id"], name: "index_steps_on_protocol_id", using: :btree - add_index "steps", ["user_id"], name: "index_steps_on_user_id", using: :btree - - create_table "tables", force: :cascade do |t| - t.binary "contents", 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" + create_table "tables", id: :serial, force: :cascade do |t| + t.binary "contents", 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.tsvector "data_vector" - t.string "name", default: "" - t.integer "team_id" + t.string "name", default: "" + t.integer "team_id" + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_tables_on_name", using: :gin + t.index ["created_at"], name: "index_tables_on_created_at" + t.index ["created_by_id"], name: "index_tables_on_created_by_id" + t.index ["data_vector"], name: "index_tables_on_data_vector", using: :gin + t.index ["last_modified_by_id"], name: "index_tables_on_last_modified_by_id" + t.index ["team_id"], name: "index_tables_on_team_id" end - add_index "tables", ["created_at"], name: "index_tables_on_created_at", using: :btree - add_index "tables", ["created_by_id"], name: "index_tables_on_created_by_id", using: :btree - add_index "tables", ["data_vector"], name: "index_tables_on_data_vector", using: :gin - add_index "tables", ["last_modified_by_id"], name: "index_tables_on_last_modified_by_id", using: :btree - add_index "tables", ["team_id"], name: "index_tables_on_team_id", using: :btree - - create_table "tags", force: :cascade do |t| - t.string "name", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "color", default: "#ff0000", null: false - t.integer "project_id", null: false - t.integer "created_by_id" - t.integer "last_modified_by_id" + create_table "tags", id: :serial, force: :cascade do |t| + t.string "name", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "color", default: "#ff0000", null: false + t.integer "project_id", null: false + t.integer "created_by_id" + t.integer "last_modified_by_id" + t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_tags_on_name", using: :gin + t.index ["created_by_id"], name: "index_tags_on_created_by_id" + t.index ["last_modified_by_id"], name: "index_tags_on_last_modified_by_id" + t.index ["project_id"], name: "index_tags_on_project_id" end - add_index "tags", ["created_by_id"], name: "index_tags_on_created_by_id", using: :btree - add_index "tags", ["last_modified_by_id"], name: "index_tags_on_last_modified_by_id", using: :btree - 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 + create_table "teams", id: :serial, 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.bigint "space_taken", default: 1048576, null: false + t.index ["created_by_id"], name: "index_teams_on_created_by_id" + t.index ["last_modified_by_id"], name: "index_teams_on_last_modified_by_id" + t.index ["name"], name: "index_teams_on_name" 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 - t.datetime "updated_at", null: false - t.string "file_file_name" - t.string "file_content_type" - t.integer "file_file_size" + create_table "temp_files", id: :serial, force: :cascade do |t| + t.string "session_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "file_file_name" + t.string "file_content_type" + t.integer "file_file_size" t.datetime "file_updated_at" end - create_table "tiny_mce_assets", force: :cascade do |t| - t.string "image_file_name" - t.string "image_content_type" - t.integer "image_file_size" + create_table "tiny_mce_assets", id: :serial, force: :cascade do |t| + t.string "image_file_name" + t.string "image_content_type" + t.integer "image_file_size" t.datetime "image_updated_at" - t.integer "estimated_size", default: 0, null: false - t.integer "step_id" - t.integer "team_id" - t.integer "result_text_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.integer "estimated_size", default: 0, null: false + t.integer "step_id" + t.integer "team_id" + t.integer "result_text_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["result_text_id"], name: "index_tiny_mce_assets_on_result_text_id" + t.index ["step_id"], name: "index_tiny_mce_assets_on_step_id" + t.index ["team_id"], name: "index_tiny_mce_assets_on_team_id" end - add_index "tiny_mce_assets", ["result_text_id"], name: "index_tiny_mce_assets_on_result_text_id", using: :btree - add_index "tiny_mce_assets", ["step_id"], name: "index_tiny_mce_assets_on_step_id", using: :btree - add_index "tiny_mce_assets", ["team_id"], name: "index_tiny_mce_assets_on_team_id", using: :btree - - create_table "tokens", force: :cascade do |t| - t.string "token", null: false - t.integer "ttl", null: false + create_table "tokens", id: :serial, force: :cascade do |t| + t.string "token", null: false + t.integer "ttl", null: false t.integer "user_id", null: false end - create_table "user_my_modules", force: :cascade do |t| - t.integer "user_id", null: false - t.integer "my_module_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "assigned_by_id" + create_table "user_my_modules", id: :serial, force: :cascade do |t| + t.integer "user_id", null: false + t.integer "my_module_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "assigned_by_id" + t.index ["assigned_by_id"], name: "index_user_my_modules_on_assigned_by_id" + t.index ["my_module_id"], name: "index_user_my_modules_on_my_module_id" + t.index ["user_id"], name: "index_user_my_modules_on_user_id" end - add_index "user_my_modules", ["assigned_by_id"], name: "index_user_my_modules_on_assigned_by_id", using: :btree - add_index "user_my_modules", ["my_module_id"], name: "index_user_my_modules_on_my_module_id", using: :btree - add_index "user_my_modules", ["user_id"], name: "index_user_my_modules_on_user_id", using: :btree - - create_table "user_notifications", force: :cascade do |t| - t.integer "user_id" - t.integer "notification_id" - t.boolean "checked", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "user_notifications", id: :serial, force: :cascade do |t| + t.integer "user_id" + t.integer "notification_id" + t.boolean "checked", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["checked"], name: "index_user_notifications_on_checked" + t.index ["notification_id"], name: "index_user_notifications_on_notification_id" + t.index ["user_id"], name: "index_user_notifications_on_user_id" end - add_index "user_notifications", ["checked"], name: "index_user_notifications_on_checked", using: :btree - 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_projects", force: :cascade do |t| - t.integer "role" - t.integer "user_id", null: false - t.integer "project_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "assigned_by_id" + create_table "user_projects", id: :serial, force: :cascade do |t| + t.integer "role" + t.integer "user_id", null: false + t.integer "project_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "assigned_by_id" + t.index ["assigned_by_id"], name: "index_user_projects_on_assigned_by_id" + t.index ["project_id"], name: "index_user_projects_on_project_id" + t.index ["user_id"], name: "index_user_projects_on_user_id" end - add_index "user_projects", ["assigned_by_id"], name: "index_user_projects_on_assigned_by_id", using: :btree - 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" + create_table "user_teams", id: :serial, 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" + t.index ["assigned_by_id"], name: "index_user_teams_on_assigned_by_id" + t.index ["team_id"], name: "index_user_teams_on_team_id" + t.index ["user_id"], name: "index_user_teams_on_user_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 - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + create_table "users", id: :serial, force: :cascade do |t| + t.string "full_name", null: false + t.string "initials", null: false + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "avatar_file_name" - t.string "avatar_content_type" - t.integer "avatar_file_size" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "avatar_file_name" + t.string "avatar_content_type" + t.integer "avatar_file_size" t.datetime "avatar_updated_at" - t.string "confirmation_token" + t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" - t.string "time_zone", default: "UTC" - t.string "invitation_token" + t.string "unconfirmed_email" + t.string "invitation_token" t.datetime "invitation_created_at" t.datetime "invitation_sent_at" t.datetime "invitation_accepted_at" - t.integer "invitation_limit" - t.integer "invited_by_id" - t.string "invited_by_type" - t.integer "invitations_count", default: 0 - t.integer "tutorial_status", default: 0, null: false - t.boolean "assignments_notification", default: true - t.boolean "recent_notification", default: true - t.boolean "assignments_notification_email", default: false - t.boolean "recent_notification_email", default: false - t.integer "current_team_id" - t.boolean "system_message_notification_email", default: false - t.string "authentication_token", limit: 30 + t.integer "invitation_limit" + t.string "invited_by_type" + t.integer "invited_by_id" + t.integer "invitations_count", default: 0 + t.integer "tutorial_status", default: 0, null: false + t.integer "current_team_id" + t.string "authentication_token", limit: 30 + t.jsonb "settings", default: {}, null: false + t.index "trim_html_tags((full_name)::text) gin_trgm_ops", name: "index_users_on_full_name", using: :gin + t.index ["authentication_token"], name: "index_users_on_authentication_token", unique: true + t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true + t.index ["invitations_count"], name: "index_users_on_invitations_count" + t.index ["invited_by_id"], name: "index_users_on_invited_by_id" + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end - add_index "users", ["authentication_token"], name: "index_users_on_authentication_token", unique: true, using: :btree - add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree - add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree - add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree - add_index "users", ["invitations_count"], name: "index_users_on_invitations_count", using: :btree - add_index "users", ["invited_by_id"], name: "index_users_on_invited_by_id", using: :btree - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree - - create_table "wopi_actions", force: :cascade do |t| - t.string "action", null: false - t.string "extension", null: false - t.string "urlsrc", null: false + create_table "wopi_actions", id: :serial, force: :cascade do |t| + t.string "action", null: false + t.string "extension", null: false + t.string "urlsrc", null: false t.integer "wopi_app_id", null: false + t.index ["extension", "action"], name: "index_wopi_actions_on_extension_and_action" end - add_index "wopi_actions", ["extension", "action"], name: "index_wopi_actions_on_extension_and_action", using: :btree - - create_table "wopi_apps", force: :cascade do |t| - t.string "name", null: false - t.string "icon", null: false + create_table "wopi_apps", id: :serial, force: :cascade do |t| + t.string "name", null: false + t.string "icon", null: false t.integer "wopi_discovery_id", null: false end - create_table "wopi_discoveries", force: :cascade do |t| - t.integer "expires", null: false - t.string "proof_key_mod", null: false - t.string "proof_key_exp", null: false - t.string "proof_key_old_mod", null: false - t.string "proof_key_old_exp", null: false + create_table "wopi_discoveries", id: :serial, force: :cascade do |t| + t.integer "expires", null: false + t.string "proof_key_mod", null: false + t.string "proof_key_exp", null: false + t.string "proof_key_old_mod", null: false + t.string "proof_key_old_exp", null: false end - create_table "zip_exports", force: :cascade do |t| - t.integer "user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "zip_file_file_name" - t.string "zip_file_content_type" - t.integer "zip_file_file_size" + create_table "zip_exports", id: :serial, force: :cascade do |t| + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "zip_file_file_name" + t.string "zip_file_content_type" + t.integer "zip_file_file_size" t.datetime "zip_file_updated_at" + t.index ["user_id"], name: "index_zip_exports_on_user_id" end - add_index "zip_exports", ["user_id"], name: "index_zip_exports_on_user_id", using: :btree - add_foreign_key "activities", "experiments" add_foreign_key "activities", "my_modules" add_foreign_key "activities", "projects" @@ -932,4 +903,22 @@ ActiveRecord::Schema.define(version: 20170515141252) do add_foreign_key "wopi_actions", "wopi_apps" add_foreign_key "wopi_apps", "wopi_discoveries" add_foreign_key "zip_exports", "users" + + create_view "datatables_teams", sql_definition: <<-SQL + SELECT teams.id, + teams.name, + user_teams.role, + ( SELECT count(*) AS count + FROM user_teams user_teams_1 + WHERE (user_teams_1.team_id = teams.id)) AS members, + CASE + WHEN (teams.created_by_id = user_teams.user_id) THEN false + ELSE true + END AS can_be_leaved, + user_teams.id AS user_team_id, + user_teams.user_id + FROM (teams + JOIN user_teams ON ((teams.id = user_teams.team_id))); + SQL + end diff --git a/db/views/datatables_teams_v01.sql b/db/views/datatables_teams_v01.sql new file mode 100644 index 000000000..25ed66b2a --- /dev/null +++ b/db/views/datatables_teams_v01.sql @@ -0,0 +1,13 @@ +SELECT + teams.id AS id, + teams.name AS name, + user_teams.role AS role, + ( + SELECT COUNT(*) + FROM user_teams + WHERE user_teams.team_id = teams.id + ) AS members, + CASE WHEN teams.created_by_id = user_teams.user_id THEN false ELSE true END AS can_be_leaved, + user_teams.id AS user_team_id, + user_teams.user_id AS user_id +FROM teams INNER JOIN user_teams ON teams.id=user_teams.team_id diff --git a/spec/factories/my_module_groups.rb b/spec/factories/my_module_groups.rb index 3688ad772..bb38bab2c 100644 --- a/spec/factories/my_module_groups.rb +++ b/spec/factories/my_module_groups.rb @@ -1,6 +1,5 @@ FactoryGirl.define do factory :my_module_group do - name Faker::Name.unique.name experiment { Experiment.first || create(:experiment_two) } end end diff --git a/spec/models/datatables/teams_spec.rb b/spec/models/datatables/teams_spec.rb new file mode 100644 index 000000000..ab740da84 --- /dev/null +++ b/spec/models/datatables/teams_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe Datatables::DatatablesTeam, type: :model do + describe 'Database table' do + it { should have_db_column :id } + it { should have_db_column :name } + it { should have_db_column :members } + it { should have_db_column :role } + it { should have_db_column :user_team_id } + it { should have_db_column :user_id } + end + + describe 'is readonly' do + let(:user) { create :user } + it do + expect { + Datatables::DatatablesTeam.create!(user_id: user.id) + }.to raise_error(ActiveRecord::ReadOnlyRecord, + 'Datatables::DatatablesTeam is marked as readonly') + end + end +end diff --git a/spec/models/my_module_group_spec.rb b/spec/models/my_module_group_spec.rb index 507d74d8e..e4e6072b6 100644 --- a/spec/models/my_module_group_spec.rb +++ b/spec/models/my_module_group_spec.rb @@ -7,7 +7,6 @@ describe MyModuleGroup, type: :model do describe 'Database table' do it { should have_db_column :id } - it { should have_db_column :name } it { should have_db_column :created_at } it { should have_db_column :updated_at } it { should have_db_column :created_by_id } @@ -21,8 +20,6 @@ describe MyModuleGroup, type: :model do end describe 'Should be a valid object' do - it { should validate_presence_of :name } it { should validate_presence_of :experiment } - it { should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH) } end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b24b6926a..affe9f36c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,6 +18,7 @@ require 'simplecov' require 'faker' require 'active_record' require 'bullet' +require 'json_matchers/rspec' RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate