Skip to content

Commit 7ef0c5e

Browse files
committed
migrations to extend dendrorelated data storage in accordance with TriDaS
1 parent a14365a commit 7ef0c5e

File tree

6 files changed

+168
-46
lines changed

6 files changed

+168
-46
lines changed

app/models/dendro.rb

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,44 @@
22
#
33
# Table name: dendros
44
#
5-
# id :bigint not null, primary key
6-
# description :text
7-
# end_year :integer
8-
# is_anchored :boolean default(FALSE)
9-
# measurements :jsonb not null
10-
# name :string not null
11-
# offset :integer
12-
# series_code :string not null
13-
# start_year :integer
14-
# created_at :datetime not null
15-
# updated_at :datetime not null
16-
# sample_id :bigint not null
5+
# id :bigint not null, primary key
6+
# death_year :integer
7+
# description :text
8+
# end_year :integer
9+
# first_year :integer
10+
# is_anchored :boolean default(FALSE)
11+
# last_year :integer
12+
# measurements :jsonb not null
13+
# name :string not null
14+
# object_description :text
15+
# object_dimensions :jsonb
16+
# object_title :string
17+
# object_type :string
18+
# offset :integer
19+
# parameters :jsonb
20+
# pith_year :integer
21+
# project_end_date :datetime
22+
# project_objective :text
23+
# project_start_date :datetime
24+
# project_title :string
25+
# series_code :string not null
26+
# start_year :integer
27+
# wood_completeness :jsonb
28+
# created_at :datetime not null
29+
# updated_at :datetime not null
30+
# chronology_id :bigint
31+
# sample_id :bigint not null
1732
#
1833
# Indexes
1934
#
20-
# index_dendros_on_measurements (measurements) USING gin
21-
# index_dendros_on_sample_id (sample_id)
22-
# index_dendros_on_series_code (series_code) UNIQUE
35+
# index_dendros_on_chronology_id (chronology_id)
36+
# index_dendros_on_measurements (measurements) USING gin
37+
# index_dendros_on_sample_id (sample_id)
38+
# index_dendros_on_series_code (series_code) UNIQUE
2339
#
2440
# Foreign Keys
2541
#
42+
# fk_rails_... (chronology_id => chronologies.id)
2643
# fk_rails_... (sample_id => samples.id)
2744
#
2845
class Dendro < ApplicationRecord
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class CreateChronologies < ActiveRecord::Migration[7.0]
2+
def change
3+
create_table :chronologies do |t|
4+
t.string :name
5+
t.string :type
6+
t.string :method
7+
t.string :standardizing_method
8+
t.string :certainty
9+
t.jsonb :parameters, default: {}
10+
t.timestamps
11+
end
12+
end
13+
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class UpdateDendrosForChronologiesAndMetadata < ActiveRecord::Migration[7.0]
2+
def change
3+
change_table :dendros do |t|
4+
# Project-level metadata
5+
t.string :project_title
6+
t.text :project_objective
7+
t.datetime :project_start_date
8+
t.datetime :project_end_date
9+
10+
# Object-level metadata
11+
t.string :object_title
12+
t.string :object_type
13+
t.text :object_description
14+
t.jsonb :object_dimensions, default: {}
15+
16+
# Dendrochronological interpretation
17+
t.integer :pith_year
18+
t.integer :death_year
19+
t.integer :first_year
20+
t.integer :last_year
21+
t.jsonb :wood_completeness, default: {}
22+
23+
# Chronology foreign key
24+
t.bigint :chronology_id, index: true
25+
t.jsonb :parameters, default: {}
26+
end
27+
28+
add_foreign_key :dendros, :chronologies
29+
end
30+
end

db/schema.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2024_12_15_123653) do
13+
ActiveRecord::Schema[7.0].define(version: 2024_12_16_082922) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_trgm"
1616
enable_extension "plpgsql"
@@ -101,6 +101,17 @@
101101
t.index ["type", "c14_age", "c14_error", "c14_curve"], name: "index_cals_on_type_and_c14_age_and_c14_error_and_c14_curve", unique: true
102102
end
103103

104+
create_table "chronologies", force: :cascade do |t|
105+
t.string "name"
106+
t.string "type"
107+
t.string "method"
108+
t.string "standardizing_method"
109+
t.string "certainty"
110+
t.jsonb "parameters", default: {}
111+
t.datetime "created_at", null: false
112+
t.datetime "updated_at", null: false
113+
end
114+
104115
create_table "citations", force: :cascade do |t|
105116
t.bigint "reference_id"
106117
t.string "citing_type"
@@ -132,6 +143,22 @@
132143
t.jsonb "measurements", default: [], null: false
133144
t.datetime "created_at", null: false
134145
t.datetime "updated_at", null: false
146+
t.string "project_title"
147+
t.text "project_objective"
148+
t.datetime "project_start_date"
149+
t.datetime "project_end_date"
150+
t.string "object_title"
151+
t.string "object_type"
152+
t.text "object_description"
153+
t.jsonb "object_dimensions", default: {}
154+
t.integer "pith_year"
155+
t.integer "death_year"
156+
t.integer "first_year"
157+
t.integer "last_year"
158+
t.jsonb "wood_completeness", default: {}
159+
t.bigint "chronology_id"
160+
t.jsonb "parameters", default: {}
161+
t.index ["chronology_id"], name: "index_dendros_on_chronology_id"
135162
t.index ["measurements"], name: "index_dendros_on_measurements", using: :gin
136163
t.index ["sample_id"], name: "index_dendros_on_sample_id"
137164
t.index ["series_code"], name: "index_dendros_on_series_code", unique: true
@@ -383,6 +410,7 @@
383410

384411
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
385412
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
413+
add_foreign_key "dendros", "chronologies"
386414
add_foreign_key "dendros", "samples"
387415
add_foreign_key "import_tables", "users"
388416
add_foreign_key "oauth_access_grants", "oauth_applications", column: "application_id"

spec/factories/dendros.rb

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,44 @@
22
#
33
# Table name: dendros
44
#
5-
# id :bigint not null, primary key
6-
# description :text
7-
# end_year :integer
8-
# is_anchored :boolean default(FALSE)
9-
# measurements :jsonb not null
10-
# name :string not null
11-
# offset :integer
12-
# series_code :string not null
13-
# start_year :integer
14-
# created_at :datetime not null
15-
# updated_at :datetime not null
16-
# sample_id :bigint not null
5+
# id :bigint not null, primary key
6+
# death_year :integer
7+
# description :text
8+
# end_year :integer
9+
# first_year :integer
10+
# is_anchored :boolean default(FALSE)
11+
# last_year :integer
12+
# measurements :jsonb not null
13+
# name :string not null
14+
# object_description :text
15+
# object_dimensions :jsonb
16+
# object_title :string
17+
# object_type :string
18+
# offset :integer
19+
# parameters :jsonb
20+
# pith_year :integer
21+
# project_end_date :datetime
22+
# project_objective :text
23+
# project_start_date :datetime
24+
# project_title :string
25+
# series_code :string not null
26+
# start_year :integer
27+
# wood_completeness :jsonb
28+
# created_at :datetime not null
29+
# updated_at :datetime not null
30+
# chronology_id :bigint
31+
# sample_id :bigint not null
1732
#
1833
# Indexes
1934
#
20-
# index_dendros_on_measurements (measurements) USING gin
21-
# index_dendros_on_sample_id (sample_id)
22-
# index_dendros_on_series_code (series_code) UNIQUE
35+
# index_dendros_on_chronology_id (chronology_id)
36+
# index_dendros_on_measurements (measurements) USING gin
37+
# index_dendros_on_sample_id (sample_id)
38+
# index_dendros_on_series_code (series_code) UNIQUE
2339
#
2440
# Foreign Keys
2541
#
42+
# fk_rails_... (chronology_id => chronologies.id)
2643
# fk_rails_... (sample_id => samples.id)
2744
#
2845
FactoryBot.define do

spec/models/dendro_spec.rb

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,44 @@
22
#
33
# Table name: dendros
44
#
5-
# id :bigint not null, primary key
6-
# description :text
7-
# end_year :integer
8-
# is_anchored :boolean default(FALSE)
9-
# measurements :jsonb not null
10-
# name :string not null
11-
# offset :integer
12-
# series_code :string not null
13-
# start_year :integer
14-
# created_at :datetime not null
15-
# updated_at :datetime not null
16-
# sample_id :bigint not null
5+
# id :bigint not null, primary key
6+
# death_year :integer
7+
# description :text
8+
# end_year :integer
9+
# first_year :integer
10+
# is_anchored :boolean default(FALSE)
11+
# last_year :integer
12+
# measurements :jsonb not null
13+
# name :string not null
14+
# object_description :text
15+
# object_dimensions :jsonb
16+
# object_title :string
17+
# object_type :string
18+
# offset :integer
19+
# parameters :jsonb
20+
# pith_year :integer
21+
# project_end_date :datetime
22+
# project_objective :text
23+
# project_start_date :datetime
24+
# project_title :string
25+
# series_code :string not null
26+
# start_year :integer
27+
# wood_completeness :jsonb
28+
# created_at :datetime not null
29+
# updated_at :datetime not null
30+
# chronology_id :bigint
31+
# sample_id :bigint not null
1732
#
1833
# Indexes
1934
#
20-
# index_dendros_on_measurements (measurements) USING gin
21-
# index_dendros_on_sample_id (sample_id)
22-
# index_dendros_on_series_code (series_code) UNIQUE
35+
# index_dendros_on_chronology_id (chronology_id)
36+
# index_dendros_on_measurements (measurements) USING gin
37+
# index_dendros_on_sample_id (sample_id)
38+
# index_dendros_on_series_code (series_code) UNIQUE
2339
#
2440
# Foreign Keys
2541
#
42+
# fk_rails_... (chronology_id => chronologies.id)
2643
# fk_rails_... (sample_id => samples.id)
2744
#
2845
require 'rails_helper'

0 commit comments

Comments
 (0)