-
-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #790 from flippercloud/mysql-fix
ActiveRecord adapter: Fix migration error for MySQL
- Loading branch information
Showing
12 changed files
with
414 additions
and
184 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
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
22 changes: 22 additions & 0 deletions
22
lib/generators/flipper/templates/update/migrations/01_create_flipper_tables.rb.erb
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,22 @@ | ||
class CreateFlipperTables < ActiveRecord::Migration<%= migration_version %> | ||
def up | ||
create_table :flipper_features do |t| | ||
t.string :key, null: false | ||
t.timestamps null: false | ||
end | ||
add_index :flipper_features, :key, unique: true | ||
|
||
create_table :flipper_gates do |t| | ||
t.string :feature_key, null: false | ||
t.string :key, null: false | ||
t.string :value | ||
t.timestamps null: false | ||
end | ||
add_index :flipper_gates, [:feature_key, :key, :value], unique: true | ||
end | ||
|
||
def down | ||
drop_table :flipper_gates | ||
drop_table :flipper_features | ||
end | ||
end |
18 changes: 18 additions & 0 deletions
18
...nerators/flipper/templates/update/migrations/02_change_flipper_gates_value_to_text.rb.erb
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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
class ChangeFlipperGatesValueToText < ActiveRecord::Migration<%= migration_version %> | ||
def up | ||
# Ensure this incremental update migration is idempotent | ||
return unless connection.column_exists? :flipper_gates, :value, :string | ||
|
||
if index_exists? :flipper_gates, [:feature_key, :key, :value] | ||
remove_index :flipper_gates, [:feature_key, :key, :value] | ||
end | ||
change_column :flipper_gates, :value, :text | ||
add_index :flipper_gates, [:feature_key, :key, :value], unique: true, length: { value: 255 } | ||
end | ||
|
||
def down | ||
change_column :flipper_gates, :value, :string | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails/generators' | ||
require 'rails/generators/active_record' | ||
|
||
module Flipper | ||
module Generators | ||
# | ||
# Rails generator used for updating Flipper in a Rails application. | ||
# Run it with +bin/rails g flipper:update+ in your console. | ||
# | ||
class UpdateGenerator < Rails::Generators::Base | ||
include ActiveRecord::Generators::Migration | ||
|
||
TEMPLATES = File.join(File.dirname(__FILE__), 'templates/update') | ||
source_paths << TEMPLATES | ||
|
||
# Generates incremental migration files unless they already exist. | ||
# All migrations should be idempotent e.g. +add_index+ is guarded with +if_index_exists?+ | ||
def update_migration_files | ||
migration_templates = Dir.children(File.join(TEMPLATES, 'migrations')).sort | ||
migration_templates.each do |template_file| | ||
destination_file = template_file.match(/^\d*_(.*\.rb)/)[1] # 01_create_flipper_tables.rb.erb => create_flipper_tables.rb | ||
migration_template "migrations/#{template_file}", File.join(db_migrate_path, destination_file), skip: true | ||
end | ||
end | ||
|
||
private | ||
|
||
def migration_version | ||
"[#{ActiveRecord::VERSION::STRING.to_f}]" | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.