diff --git a/api/Gemfile b/api/Gemfile index b25e05b1..516ccfd9 100644 --- a/api/Gemfile +++ b/api/Gemfile @@ -21,6 +21,7 @@ gem 'rack-cors' gem 'rambulance' gem 'sentry-rails' gem 'sentry-sidekiq' +gem 'sequel' gem 'sidekiq' gem 'sidekiq-scheduler' gem 'submission-excel2xml', github: 'ddbj/submission-excel2xml' diff --git a/api/Gemfile.lock b/api/Gemfile.lock index a312448b..322c887b 100644 --- a/api/Gemfile.lock +++ b/api/Gemfile.lock @@ -341,6 +341,8 @@ GEM sentry-sidekiq (5.17.3) sentry-ruby (~> 5.17.3) sidekiq (>= 3.0) + sequel (5.81.0) + bigdecimal sidekiq (7.2.4) concurrent-ruby (< 2) connection_pool (>= 2.3.0) @@ -416,6 +418,7 @@ DEPENDENCIES rspec-rails sentry-rails sentry-sidekiq + sequel sidekiq sidekiq-scheduler skooma diff --git a/api/app/models/database/dra.rb b/api/app/models/database/dra.rb index 88d6b4f0..01819815 100644 --- a/api/app/models/database/dra.rb +++ b/api/app/models/database/dra.rb @@ -50,7 +50,43 @@ def validate(validation) class Submitter def submit(submission) - # do nothing + db = Sequel.connect(ENV.fetch('DRA_DATABASE_URL')) + + user_id = 42 + submitter_id = '42' + serial = (db[:submission].where(submitter_id:).max(:serial) || 0) + 1 + submission_id = "#{submitter_id}-#{serial.to_s.rjust(4, '0')}" + + sub_id = db[:submission].insert( + usr_id: user_id, + submitter_id: , + serial: , + create_date: Date.current + ) + + db[:status_history].insert( + sub_id: , + status: 100 # SubmissionStatus.NEW + ) + + db[:operation_history].insert( + type: 3, # LogLevel.INFO + summary: 'Status update to new', + usr_id: user_id, + serial: , + submitter_id: + ) + + ext_id = db[:ext_entity].insert( + acc_type: 'DRA', + ref_name: submission_id, + status: 0 # ExtStatus.INPUTTING + ) + + db[:ext_permit].insert( + ext_id: , + submitter_id: + ) end end end diff --git a/api/app/models/database/dra/db/migrations/001_init.rb b/api/app/models/database/dra/db/migrations/001_init.rb new file mode 100644 index 00000000..22bd1229 --- /dev/null +++ b/api/app/models/database/dra/db/migrations/001_init.rb @@ -0,0 +1,53 @@ +Sequel.migration do + change do + create_table :submission do + primary_key :sub_id, type: :bigint + + bigint :usr_id, null: false + text :submitter_id, null: false + integer :serial, null: false + integer :charge + date :create_date + date :submit_date + date :hold_date + date :dist_date + date :finish_date + text :note + end + + create_table :status_history do + primary_key :id, type: :bigint + + bigint :sub_id + integer :status + timestamp :date + end + + create_table :operation_history do + primary_key :his_id, type: :bigint + + integer :type + text :summary + text :file_name + timestamp :date + bigint :usr_id + integer :serial + text :submitter_id + end + + create_table :ext_entity do + primary_key :ext_id, type: :bigint + + text :acc_type + text :ref_name + integer :status + end + + create_table :ext_permit do + primary_key :per_id, type: :bigint + + bigint :ext_id + text :submitter_id + end + end +end diff --git a/api/lib/tasks/dra.rake b/api/lib/tasks/dra.rake new file mode 100644 index 00000000..5afa5a86 --- /dev/null +++ b/api/lib/tasks/dra.rake @@ -0,0 +1,14 @@ +namespace :dra do + namespace :db do + desc 'Run migrations' + task :migrate, [:version] do |t, args| + require 'sequel/core' + + Sequel.extension :migration + + Sequel.connect ENV.fetch('DRA_DATABASE_URL') do |db| + Sequel::Migrator.run db, 'app/models/database/dra/db/migrations', target: args[:version]&.to_i + end + end + end +end