Skip to content

Commit

Permalink
[db] Hardcode encoding in old migrations
Browse files Browse the repository at this point in the history
The old migrations are tested on current database and database
settings. This makes it bound to the current encoding - and that is
utf8mb4. But without Barracuda tables you can't have varchars. So hardcode
the encoding used in 2017 by using execute instead of rails helpers

On create it's easy to add, but renames and other column changes
need to be changed to executes as they otherwise drop the charset
  • Loading branch information
coolo committed Aug 1, 2018
1 parent 8651079 commit 8667ff5
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/api/.rubocop.yml
Expand Up @@ -76,6 +76,7 @@ Rails/BulkChangeTable:
- 'db/migrate/20170516140442_add_several_fields_to_kiwi_repositories.rb'
- 'db/migrate/20170607110443_add_and_remove_some_index_in_bs_request_actions.rb'
- 'db/migrate/20170630121602_add_index_bs_requests_action.rb'
- 'db/migrate/20170619111734_alter_notifications_to_use_polymorphic.rb'
- 'db/migrate/20170905081525_add_has_secure_password_support.rb'
- 'db/migrate/20170911142301_change_kiwi_package_groups_columns_from_big_int_to_int.rb'
- 'db/migrate/20170912140257_change_kiwi_packages_columns_from_big_int_to_int.rb'
Expand Down
2 changes: 1 addition & 1 deletion src/api/db/migrate/20140624101042_add_package_tracking.rb
Expand Up @@ -7,7 +7,7 @@ def up

t.integer :release_package_id

t.string :binary_name, null: false
t.string :binary_name, null: false, charset: 'utf8'
t.string :binary_epoch, limit: 64
t.string :binary_version, null: false, limit: 64
t.string :binary_release, null: false, limit: 64
Expand Down
Expand Up @@ -3,7 +3,7 @@ def up
create_table :product_media do |t|
t.references :product
t.references :repository
t.string :medium
t.string :medium, charset: 'utf8'
end

execute('alter table product_media add foreign key (product_id) references products(id)')
Expand Down
@@ -1,6 +1,6 @@
class ProductMediumTracking < ActiveRecord::Migration[4.2]
def up
add_column :binary_releases, :medium, :string
add_column :binary_releases, :medium, :string, charset: 'utf8'
end

def down
Expand Down
Expand Up @@ -4,7 +4,7 @@ def up
t.references :repository, null: false
t.references :package, null: false
t.datetime :created_at, null: false
t.string :identifier, null: false
t.string :identifier, null: false, charset: 'utf8'
end

add_index :updateinfos, :identifier
Expand Down
@@ -1,6 +1,6 @@
class UpdateinfoTrackingSecondAttempt < ActiveRecord::Migration[4.2]
def up
add_column :binary_releases, :binary_updateinfo, :string
add_column :binary_releases, :binary_updateinfo, :string, charset: 'utf8'
add_column :binary_releases, :binary_updateinfo_version, :string
add_index :binary_releases, :binary_updateinfo

Expand Down
Expand Up @@ -5,7 +5,7 @@ def up
add_column :products, :patchlevel, :string
add_column :products, :release, :string

rename_column :product_media, :medium, :name
execute 'ALTER TABLE `product_media` CHANGE `medium` `name` varchar(255) CHARSET utf8 DEFAULT NULL'
end

def down
Expand Down
@@ -1,7 +1,7 @@
class AddGenericOperationHistory < ActiveRecord::Migration[4.2]
def self.up
create_table :history_elements do |t|
t.string :type, null: false
t.string :type, charset: 'utf8', null: false
t.integer :op_object_id, null: false # id of request/project/...
t.datetime :created_at, null: false
t.references :user, null: false
Expand Down
Expand Up @@ -15,7 +15,7 @@ def self.up
t.references :product
t.references :repository
t.integer :arch_filter_id
t.string :name
t.string :name, charset: 'utf8'
end
add_index :product_media, :product_id
add_index :product_media, :arch_filter_id
Expand Down
Expand Up @@ -4,12 +4,10 @@ def up
# otherwise we will get duplicate entry exception when we set remote_project_name to an empty string
msg = 'Pending data migration 20170306084550. Please run rake db:migrate:with_data.'
raise ActiveRecord::ActiveRecordError, msg unless DataMigrate::DataSchemaMigration.where(version: 20_170_306_084_550).exists?
change_column_null :repositories, :remote_project_name, false
change_column_default :repositories, :remote_project_name, ''
execute "ALTER TABLE `repositories` CHANGE `remote_project_name` `remote_project_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT ''"
end

def down
change_column_null :repositories, :remote_project_name, true
change_column_default :repositories, :remote_project_name, nil
execute 'ALTER TABLE `repositories` CHANGE `remote_project_name` `remote_project_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL'
end
end
@@ -1,6 +1,8 @@
class AlterNotificationsToUsePolymorphic < ActiveRecord::Migration[5.0]
def change
add_reference :notifications, :subscriber, polymorphic: true
add_column(:notifications, 'subscriber_type', :string, charset: 'utf8')
add_column(:notifications, 'subscriber_id', :integer)
add_index(:notifications, ['subscriber_type', 'subscriber_id'])

# Existing notifications would fail because of incompatible payload.
# Since this is for a feature that just got introduced we can drop them.
Expand Down
4 changes: 2 additions & 2 deletions src/api/db/migrate/20171218160607_create_ec2_configuration.rb
Expand Up @@ -2,8 +2,8 @@ class CreateEc2Configuration < ActiveRecord::Migration[5.1]
def change
create_table :cloud_ec2_configurations, id: :integer do |t|
t.belongs_to :user, index: true, type: :integer
t.string :external_id
t.string :arn
t.string :external_id, charset: 'utf8'
t.string :arn, charset: 'utf8'

t.timestamps
end
Expand Down

0 comments on commit 8667ff5

Please sign in to comment.