Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'database/bigint_migration'

table = :delayed_jobs

Sequel.migration do
up do
if database_type == :postgres && !VCAP::BigintMigration.opt_out?
if VCAP::BigintMigration.table_empty?(self, table)
VCAP::BigintMigration.change_pk_to_bigint(self, table)
else
VCAP::BigintMigration.add_bigint_column(self, table)
VCAP::BigintMigration.create_trigger_function(self, table)
end
end
end

down do
if database_type == :postgres
# There is no guarantee that the table is still empty - which was the condition for simply switching the id
# column's type to bigint. We nevertheless want to revert the type to integer as this is the opposite procedure of
# the up migration. In case there is a lot of data in the table at this moment in time, this change might be
# problematic, e.g. take a longer time.
#
# Ideally this down migration SHOULD NEVER BE EXECUTED IN A PRODUCTION SYSTEM! (It's there for proper integration
# testing of the bigint migration steps.)
VCAP::BigintMigration.revert_pk_to_integer(self, table)

VCAP::BigintMigration.drop_trigger_function(self, table)
VCAP::BigintMigration.drop_bigint_column(self, table)
end
end
end
32 changes: 32 additions & 0 deletions db/migrations/20250729142900_bigint_migration_jobs_step1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'database/bigint_migration'

table = :jobs

Sequel.migration do
up do
if database_type == :postgres && !VCAP::BigintMigration.opt_out?
if VCAP::BigintMigration.table_empty?(self, table)
VCAP::BigintMigration.change_pk_to_bigint(self, table)
else
VCAP::BigintMigration.add_bigint_column(self, table)
VCAP::BigintMigration.create_trigger_function(self, table)
end
end
end

down do
if database_type == :postgres
# There is no guarantee that the table is still empty - which was the condition for simply switching the id
# column's type to bigint. We nevertheless want to revert the type to integer as this is the opposite procedure of
# the up migration. In case there is a lot of data in the table at this moment in time, this change might be
# problematic, e.g. take a longer time.
#
# Ideally this down migration SHOULD NEVER BE EXECUTED IN A PRODUCTION SYSTEM! (It's there for proper integration
# testing of the bigint migration steps.)
VCAP::BigintMigration.revert_pk_to_integer(self, table)

VCAP::BigintMigration.drop_trigger_function(self, table)
VCAP::BigintMigration.drop_bigint_column(self, table)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'database/bigint_migration'

table = :app_usage_events

Sequel.migration do
up do
if database_type == :postgres && !VCAP::BigintMigration.opt_out?
if VCAP::BigintMigration.table_empty?(self, table)
VCAP::BigintMigration.change_pk_to_bigint(self, table)
else
VCAP::BigintMigration.add_bigint_column(self, table)
VCAP::BigintMigration.create_trigger_function(self, table)
end
end
end

down do
if database_type == :postgres
# There is no guarantee that the table is still empty - which was the condition for simply switching the id
# column's type to bigint. We nevertheless want to revert the type to integer as this is the opposite procedure of
# the up migration. In case there is a lot of data in the table at this moment in time, this change might be
# problematic, e.g. take a longer time.
#
# Ideally this down migration SHOULD NEVER BE EXECUTED IN A PRODUCTION SYSTEM! (It's there for proper integration
# testing of the bigint migration steps.)
VCAP::BigintMigration.revert_pk_to_integer(self, table)

VCAP::BigintMigration.drop_trigger_function(self, table)
VCAP::BigintMigration.drop_bigint_column(self, table)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'database/bigint_migration'

table = :service_usage_events

Sequel.migration do
up do
if database_type == :postgres && !VCAP::BigintMigration.opt_out?
if VCAP::BigintMigration.table_empty?(self, table)
VCAP::BigintMigration.change_pk_to_bigint(self, table)
else
VCAP::BigintMigration.add_bigint_column(self, table)
VCAP::BigintMigration.create_trigger_function(self, table)
end
end
end

down do
if database_type == :postgres
# There is no guarantee that the table is still empty - which was the condition for simply switching the id
# column's type to bigint. We nevertheless want to revert the type to integer as this is the opposite procedure of
# the up migration. In case there is a lot of data in the table at this moment in time, this change might be
# problematic, e.g. take a longer time.
#
# Ideally this down migration SHOULD NEVER BE EXECUTED IN A PRODUCTION SYSTEM! (It's there for proper integration
# testing of the bigint migration steps.)
VCAP::BigintMigration.revert_pk_to_integer(self, table)

VCAP::BigintMigration.drop_trigger_function(self, table)
VCAP::BigintMigration.drop_bigint_column(self, table)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'
require 'migrations/helpers/bigint_migration_step1_shared_context'

RSpec.describe 'bigint migration - delayed_jobs table - step1', isolation: :truncation, type: :migration do
include_context 'bigint migration step1' do
let(:migration_filename) { '20250729142800_bigint_migration_delayed_jobs_step1.rb' }
let(:table) { :delayed_jobs }
let(:insert) do
lambda do |db|
db[:delayed_jobs].insert(guid: SecureRandom.uuid)
end
end
end
end
14 changes: 14 additions & 0 deletions spec/migrations/20250729142900_bigint_migration_jobs_step1_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'
require 'migrations/helpers/bigint_migration_step1_shared_context'

RSpec.describe 'bigint migration - jobs table - step1', isolation: :truncation, type: :migration do
include_context 'bigint migration step1' do
let(:migration_filename) { '20250729142900_bigint_migration_jobs_step1.rb' }
let(:table) { :jobs }
let(:insert) do
lambda do |db|
db[:jobs].insert(guid: SecureRandom.uuid)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'
require 'migrations/helpers/bigint_migration_step1_shared_context'

RSpec.describe 'bigint migration - app_usage_events table - step1', isolation: :truncation, type: :migration do
include_context 'bigint migration step1' do
let(:migration_filename) { '20250729143000_bigint_migration_app_usage_events_step1.rb' }
let(:table) { :app_usage_events }
let(:insert) do
lambda do |db|
db[:app_usage_events].insert(guid: SecureRandom.uuid, created_at: Time.now.utc, instance_count: 1,
memory_in_mb_per_instance: 2, state: 'state', app_guid: 'app_guid',
app_name: 'app_name', space_guid: 'space_guid', space_name: 'space_name',
org_guid: 'org_guid')
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'
require 'migrations/helpers/bigint_migration_step1_shared_context'

RSpec.describe 'bigint migration - service_usage_events table - step1', isolation: :truncation, type: :migration do
include_context 'bigint migration step1' do
let(:migration_filename) { '20250729143100_bigint_migration_service_usage_events_step1.rb' }
let(:table) { :service_usage_events }
let(:insert) do
lambda do |db|
db[:service_usage_events].insert(guid: SecureRandom.uuid, created_at: Time.now.utc, state: 'state',
org_guid: 'org_guid', space_guid: 'space_guid', space_name: 'space_name',
service_instance_guid: 'si_guid', service_instance_name: 'si_name',
service_instance_type: 'si_type')
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
it 'fails with a proper error message' do
expect do
VCAP::BigintMigration.backfill(logger, db, table)
end.to raise_error(RuntimeError, /table 'events' does not contain column 'id_bigint'/)
end.to raise_error(RuntimeError, /table '#{table}' does not contain column 'id_bigint'/)
end
end
end
Expand Down