-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the frameworks table in preparation for the other model changes
- Loading branch information
Showing
8 changed files
with
78 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
id,service,live_at,expires_at | ||
RM6238,supply_teachers,"2022-09-12","2026-09-01" | ||
RM6187,management_consultancy,"2021-09-04","2025-09-04" | ||
RM6240,legal_services,"2022-10-03","2026-10-01" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class RefactorFrameworksTable < ActiveRecord::Migration[7.1] | ||
class FrameworkOld < ApplicationRecord | ||
self.table_name = 'frameworks_old' | ||
end | ||
|
||
class Framework < ApplicationRecord | ||
self.table_name = 'frameworks' | ||
end | ||
|
||
def up | ||
rename_table :frameworks, :frameworks_old | ||
|
||
create_table :frameworks, id: :string, limit: 6 do |t| | ||
t.string :service, limit: 25 | ||
t.date :live_at | ||
t.date :expires_at | ||
|
||
t.timestamps | ||
end | ||
|
||
FrameworkOld.find_each do |framework| | ||
Framework.create( | ||
id: framework.framework, | ||
service: framework.service, | ||
live_at: framework.live_at, | ||
expires_at: framework.expires_at | ||
) | ||
end | ||
|
||
drop_table :frameworks_old | ||
end | ||
|
||
def down | ||
create_table 'frameworks_old', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| | ||
t.string 'service', limit: 25 | ||
t.string 'framework', limit: 6 | ||
t.date 'live_at' | ||
t.timestamps | ||
t.date 'expires_at' | ||
end | ||
|
||
Framework.find_each do |framework| | ||
FrameworkOld.create( | ||
framework: framework.id, | ||
service: framework.service, | ||
live_at: framework.live_at, | ||
expires_at: framework.expires_at | ||
) | ||
end | ||
|
||
drop_table :frameworks | ||
|
||
rename_table :frameworks_old, :frameworks | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
RSpec.shared_context 'and RM6238 is live in the future' do | ||
before { Framework.find_by(framework: 'RM6238').update(live_at: 1.day.from_now) } | ||
before { Framework.find('RM6238').update(live_at: 1.day.from_now) } | ||
end | ||
|
||
RSpec.shared_context 'and RM6238 is live today' do | ||
before { Framework.find_by(framework: 'RM6238').update(live_at: Time.zone.now) } | ||
before { Framework.find('RM6238').update(live_at: Time.zone.now) } | ||
end | ||
|
||
RSpec.shared_context 'and RM6238 has expired' do | ||
before { Framework.find_by(framework: 'RM6238').update(expires_at: Time.zone.now) } | ||
before { Framework.find('RM6238').update(expires_at: Time.zone.now) } | ||
end | ||
|
||
RSpec.shared_context 'and RM6240 is live in the future' do | ||
before { Framework.find_by(framework: 'RM6240').update(live_at: 1.day.from_now) } | ||
before { Framework.find('RM6240').update(live_at: 1.day.from_now) } | ||
end | ||
|
||
RSpec.shared_context 'and RM6240 is live today' do | ||
before { Framework.find_by(framework: 'RM6240').update(live_at: Time.zone.now) } | ||
before { Framework.find('RM6240').update(live_at: Time.zone.now) } | ||
end | ||
|
||
RSpec.shared_context 'and RM6240 has expired' do | ||
before { Framework.find_by(framework: 'RM6240').update(expires_at: Time.zone.now) } | ||
before { Framework.find('RM6240').update(expires_at: Time.zone.now) } | ||
end | ||
|
||
RSpec.shared_context 'and RM6187 has expired' do | ||
before { Framework.find_by(framework: 'RM6187').update(expires_at: Time.zone.now) } | ||
before { Framework.find('RM6187').update(expires_at: Time.zone.now) } | ||
end |