From fd6888938fc74beb22c7015d8253a2053dd6dccd Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 4 May 2020 16:27:07 -0500 Subject: [PATCH] Add classes to simplify table migration and manipulation for upgrades --- .../lib/houdini_upgrade/column_to_migrate.rb | 15 +++++++++++ .../lib/houdini_upgrade/table_to_migrate.rb | 25 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 gems/houdini_upgrade/lib/houdini_upgrade/column_to_migrate.rb create mode 100644 gems/houdini_upgrade/lib/houdini_upgrade/table_to_migrate.rb diff --git a/gems/houdini_upgrade/lib/houdini_upgrade/column_to_migrate.rb b/gems/houdini_upgrade/lib/houdini_upgrade/column_to_migrate.rb new file mode 100644 index 00000000..e092ae25 --- /dev/null +++ b/gems/houdini_upgrade/lib/houdini_upgrade/column_to_migrate.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later +module HoudiniUpgrade + class ColumnToMigrate + attr_reader :name + def initialize(original_column_name) + @name = original_column_name.to_s + end + + def migrated_name + @name + "_temp" + end + end +end \ No newline at end of file diff --git a/gems/houdini_upgrade/lib/houdini_upgrade/table_to_migrate.rb b/gems/houdini_upgrade/lib/houdini_upgrade/table_to_migrate.rb new file mode 100644 index 00000000..3389fd13 --- /dev/null +++ b/gems/houdini_upgrade/lib/houdini_upgrade/table_to_migrate.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later +require_relative "./column_to_migrate" +module HoudiniUpgrade + class TableToMigrate + attr_reader :fields, :name + def initialize(original_table_name, original_field_names) + @name = original_table_name.to_s + @fields = original_field_names.map{|i| ColumnToMigrate.new(i)} + end + + def class_name + @name.classify + end + + def backup_table + @name + "_uploader_backups" + end + + def foreign_key + @name + "_id" + end + end +end \ No newline at end of file