Reworked database schema from scratch
This commit is contained in:
parent
394a8ef91f
commit
b819f4f1cd
@ -5,6 +5,7 @@ Sequel.migration do
|
|||||||
primary_key :id
|
primary_key :id
|
||||||
String :name, null: false
|
String :name, null: false
|
||||||
String :type, null: false
|
String :type, null: false
|
||||||
|
String :description, text: true
|
||||||
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
||||||
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
||||||
end
|
end
|
||||||
@ -12,28 +13,16 @@ Sequel.migration do
|
|||||||
create_table(:benchmarks) do
|
create_table(:benchmarks) do
|
||||||
primary_key :id
|
primary_key :id
|
||||||
String :name, null: false
|
String :name, null: false
|
||||||
String :description
|
String :description, text: true
|
||||||
String :scoring, null: false
|
String :scoring, null: false
|
||||||
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
||||||
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table(:results) do
|
|
||||||
primary_key :id
|
|
||||||
String :score, null: false
|
|
||||||
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
|
||||||
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
|
||||||
end
|
|
||||||
alter_table(:results) do
|
|
||||||
add_foreign_key :hardware_id, :hardware
|
|
||||||
add_foreign_key :benchmark_id, :benchmarks
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
down do
|
down do
|
||||||
drop_table(:hardware)
|
drop_table(:hardware)
|
||||||
drop_table(:benchmarks)
|
drop_table(:benchmarks)
|
||||||
drop_table(:results)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
Sequel.migration do
|
|
||||||
|
|
||||||
up do
|
|
||||||
alter_table(:results) do
|
|
||||||
add_column :type, String, null: false, default: 'fps'
|
|
||||||
add_column :minimum_score, String
|
|
||||||
add_column :maximum_score, String
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
down do
|
|
||||||
drop_column :results, :type
|
|
||||||
drop_column :results, :minimum_score
|
|
||||||
drop_column :results, :maximum_score
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
28
db/migrations/0002_add_tests_table.rb
Normal file
28
db/migrations/0002_add_tests_table.rb
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
Sequel.migration do
|
||||||
|
|
||||||
|
up do
|
||||||
|
# create tests table
|
||||||
|
create_table(:tests) do
|
||||||
|
primary_key :id
|
||||||
|
foreign_key :hardware_id, :hardware
|
||||||
|
String :date_tag, null: false
|
||||||
|
String :description, text: true
|
||||||
|
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
||||||
|
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
||||||
|
end
|
||||||
|
|
||||||
|
# create many-to-many table for benchmarks and tests
|
||||||
|
create_table(:tests_benchmarks) do
|
||||||
|
foreign_key :test_id, :tests
|
||||||
|
foreign_key :benchmark_id, :benchmarks
|
||||||
|
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
||||||
|
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
down do
|
||||||
|
drop_table(:tests_benchmarks)
|
||||||
|
drop_table(:tests)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
29
db/migrations/0003_add_results_table.rb
Normal file
29
db/migrations/0003_add_results_table.rb
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
Sequel.migration do
|
||||||
|
|
||||||
|
up do
|
||||||
|
# create tests table
|
||||||
|
create_table(:results) do
|
||||||
|
primary_key :id
|
||||||
|
foreign_key :benchmark_id, :benchmarks
|
||||||
|
Float :avg_score, null: false
|
||||||
|
Float :min_score
|
||||||
|
Float :max_score
|
||||||
|
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
||||||
|
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
||||||
|
end
|
||||||
|
|
||||||
|
# create many-to-many table for results and tests
|
||||||
|
create_table(:tests_results) do
|
||||||
|
foreign_key :test_id, :tests
|
||||||
|
foreign_key :result_id, :results
|
||||||
|
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
||||||
|
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
down do
|
||||||
|
drop_table(:tests_results)
|
||||||
|
drop_table(:results)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -1,31 +0,0 @@
|
|||||||
Sequel.migration do
|
|
||||||
|
|
||||||
up do
|
|
||||||
# create tests table
|
|
||||||
create_table(:tests) do
|
|
||||||
primary_key :id
|
|
||||||
String :date_tag, null: false
|
|
||||||
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
|
||||||
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
|
||||||
end
|
|
||||||
|
|
||||||
# add foreign keys to tests table
|
|
||||||
alter_table(:tests) do
|
|
||||||
add_foreign_key(:benchmark_id, :benchmarks, null: false)
|
|
||||||
add_foreign_key(:hardware_id, :hardware, null: false)
|
|
||||||
end
|
|
||||||
|
|
||||||
# add the test ID link to results table; remove old links to hardware and benchmarks tables
|
|
||||||
alter_table(:results) do
|
|
||||||
add_foreign_key(:test_id, :tests, null: false)
|
|
||||||
drop_column(:benchmark_id)
|
|
||||||
drop_column(:hardware_id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
down do
|
|
||||||
drop_column(:results, :test_id)
|
|
||||||
drop_table(:tests)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user