Skip to content

Commit

Permalink
Create records
Browse files Browse the repository at this point in the history
  • Loading branch information
ursm committed Jun 26, 2024
1 parent a76afff commit 4594317
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -416,6 +418,7 @@ DEPENDENCIES
rspec-rails
sentry-rails
sentry-sidekiq
sequel
sidekiq
sidekiq-scheduler
skooma
Expand Down
38 changes: 37 additions & 1 deletion api/app/models/database/dra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
53 changes: 53 additions & 0 deletions api/app/models/database/dra/db/migrations/001_init.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions api/lib/tasks/dra.rake
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4594317

Please sign in to comment.