-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
233 additions
and
43 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 was deleted.
Oops, something went wrong.
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../models/migration_version' | ||
require_relative 'service_20230613121411' | ||
require_relative 'version' | ||
|
||
module Dsu | ||
module Migration | ||
class Factory | ||
class << self | ||
def migrate_if!(options: {}) | ||
version = options.fetch(:version, migration_version) | ||
if version == 20230613121411 # rubocop:disable Style/NumericLiterals | ||
Service20230613121411.new(options: options).migrate! | ||
end | ||
end | ||
|
||
private | ||
|
||
def migration_version | ||
@migration_version ||= Models::MigrationVersion.new.version | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../support/fileable' | ||
require_relative 'version' | ||
|
||
# TODO: Read raw configuration .json file | ||
# If default_project is not set... | ||
# - Add default_project to configuration .json file and write it out. | ||
# - Reload the configuration file. | ||
# - Create a Models::Project object for the default project and initialize/save it. | ||
# - Move the old entries folder into the default project folder. | ||
# TODO: Add default_project to configuration .json file | ||
module Dsu | ||
module Migration | ||
class Service20230613121411 | ||
include Support::Fileable | ||
|
||
def initialize(options: {}) | ||
@options = options || {} | ||
end | ||
|
||
def migrate! | ||
puts 'Running migrations...' | ||
puts | ||
|
||
puts "options[:pretend] is true\n" if pretend? | ||
|
||
raise_wrong_migration_version_error_if! | ||
|
||
puts "Migrating from: #{target_migration_version} to version: #{Migration::VERSION}" | ||
puts | ||
|
||
add_new_color_themes | ||
backup | ||
create_default_project | ||
update_configuration | ||
update_entry_groups | ||
update_color_themes | ||
delete_old_entry_folder | ||
delete_old_theme_folder | ||
|
||
puts 'Migration completed successfully.' | ||
end | ||
|
||
private | ||
|
||
attr_reader :options | ||
|
||
def pretend? | ||
options.fetch(:pretend, true) | ||
end | ||
|
||
def add_new_color_themes | ||
puts 'Copying new color themes...' | ||
puts | ||
|
||
%w[light.json christmas.json].each do |theme_file| | ||
destination_theme_file_path = File.join(Dsu::Support::Fileable.themes_folder, theme_file) | ||
next if File.exist?(destination_theme_file_path) | ||
|
||
source_theme_file_path = File.join(Dsu::Support::Fileable.seed_data_folder, 'themes', theme_file) | ||
FileUtils.cp(source_theme_file_path, destination_theme_file_path) unless pretend? | ||
puts I18n.t('migrations.information.theme_copied', from: source_theme_file_path, to: destination_theme_file_path) | ||
end | ||
end | ||
|
||
def backup | ||
return if Dir.exist?(backup_folder) | ||
|
||
puts 'Creating backup...' | ||
puts | ||
|
||
FileUtils.cp_r(dsu_folder, backup_folder) unless pretend? | ||
end | ||
|
||
def create_default_project | ||
default_project = Models::Configuration::DEFAULT_CONFIGURATION[:default_project] | ||
return if Models::Project.project_initialized?(project_name: default_project) | ||
|
||
puts "Creating default project \"#{default_project}\"..." | ||
puts | ||
|
||
Models::Project.create(project_name: default_project, options: options) unless pretend? | ||
end | ||
|
||
def update_configuration | ||
puts 'Updating configuration...' | ||
puts | ||
|
||
Models::Configuration.new.write! unless pretend? | ||
end | ||
|
||
def update_entry_groups | ||
puts 'Updating entry groups...' | ||
puts | ||
|
||
return if Dir.exist?(entries_folder) || pretend? | ||
|
||
puts 'Copying entries to default project...' | ||
puts | ||
|
||
FileUtils.mkdir_p(entries_folder) | ||
FileUtils.cp_r(File.join(backup_folder, 'entries', '.'), entries_folder) | ||
|
||
puts 'Updating entry group version...' | ||
puts | ||
|
||
Models::EntryGroup.all.each do |entry_group| | ||
puts "Updating entry group version: #{entry_group.time_yyyy_mm_dd}..." | ||
entry_group.version = Dsu::Migration::VERSION | ||
entry_group.save! unless pretend? | ||
end | ||
end | ||
|
||
def update_color_themes | ||
puts 'Updating color themes...' | ||
puts | ||
|
||
return if Dir.exist?(themes_folder) || pretend? | ||
|
||
puts 'Copying color themes...' | ||
puts | ||
|
||
FileUtils.mkdir_p(themes_folder) | ||
FileUtils.cp_r(File.join(backup_folder, 'themes', '.'), themes_folder) | ||
|
||
puts 'Updating color theme version...' | ||
puts | ||
|
||
Models::ColorTheme.all.each do |color_theme| | ||
puts "Updating color theme version: #{color_theme.theme_name}..." | ||
color_theme.version = Dsu::Migration::VERSION | ||
color_theme.save! unless pretend? | ||
end | ||
end | ||
|
||
def delete_old_entry_folder | ||
puts 'Cleaning up old entries...' | ||
puts | ||
|
||
FileUtils.rm_rf(File.join(dsu_folder, 'entries')) unless pretend? | ||
end | ||
|
||
def delete_old_theme_folder | ||
puts 'Cleaning up old themes...' | ||
puts | ||
|
||
FileUtils.rm_rf(File.join(dsu_folder, 'themes')) unless pretend? | ||
end | ||
|
||
def backup_folder | ||
@backup_folder ||= File.join(dsu_folder, target_migration_version.to_s) | ||
end | ||
|
||
def target_migration_version | ||
20230613121411 # rubocop:disable Style/NumericLiterals | ||
end | ||
|
||
def raise_wrong_migration_version_error_if! | ||
return if migration_version == target_migration_version | ||
|
||
raise "Actual migration version #{migration_version} " \ | ||
"is not the expected migration version #{target_migration_version}." | ||
end | ||
|
||
def migration_version | ||
@migration_version ||= Models::MigrationVersion.new.version | ||
end | ||
end | ||
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
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,4 +1,4 @@ | ||
{ | ||
"version": 20230613121411, | ||
"version": 20240210161248, | ||
"project_name": "default" | ||
} |
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,5 +1,5 @@ | ||
project_name,version,entry_group,entry_no,total_entries,entry_group_entry | ||
default,20230613121411,2023-12-31,1,2,Entry 2023-12-31 duplicate | ||
default,20230613121411,2023-12-31,2,2,Entry 2023-12-31 duplicate | ||
default,20230613121411,2024-01-01,1,1,Entry 2024-01-01 1 of 2 | ||
default,20230613121411,2024-01-02,1,1,Entry 2024-01-02 2 of 2 | ||
default,20240210161248,2023-12-31,1,2,Entry 2023-12-31 duplicate | ||
default,20240210161248,2023-12-31,2,2,Entry 2023-12-31 duplicate | ||
default,20240210161248,2024-01-01,1,1,Entry 2024-01-01 1 of 2 | ||
default,20240210161248,2024-01-02,1,1,Entry 2024-01-02 2 of 2 |
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,5 +1,5 @@ | ||
project_name,version,entry_group,entry_no,total_entries,entry_group_entry | ||
default,20230613121411,2023-12-31,1,2, | ||
default,20230613121411,2023-12-31,2,2, | ||
default,20230613121411,2024-01-01,1,1, | ||
default,20230613121411,2024-01-02,1,1, | ||
default,20240210161248,2023-12-31,1,2, | ||
default,20240210161248,2023-12-31,2,2, | ||
default,20240210161248,2024-01-01,1,1, | ||
default,20240210161248,2024-01-02,1,1, |
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,5 +1,5 @@ | ||
project_name,version,entry_group,entry_no,total_entries,entry_group_entry | ||
default,20230613121411,2023-12-31,1,2,Entry 2023-12-31 1 of 2 | ||
default,20230613121411,2023-12-31,2,2,Entry 2023-12-31 2 of 2 | ||
default,20230613121411,2024-01-01,1,1,Entry 2024-01-01 1 of 1 | ||
default,20230613121411,2024-01-02,1,1,Entry 2024-01-02 1 of 1 | ||
default,20240210161248,2023-12-31,1,2,Entry 2023-12-31 1 of 2 | ||
default,20240210161248,2023-12-31,2,2,Entry 2023-12-31 2 of 2 | ||
default,20240210161248,2024-01-01,1,1,Entry 2024-01-01 1 of 1 | ||
default,20240210161248,2024-01-02,1,1,Entry 2024-01-02 1 of 1 |
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,5 +1,5 @@ | ||
project_name,version,entry_group,entry_no,total_entries,entry_group_entry | ||
bad-project,20230613121411,2023-12-31,1,2,Entry 2023-12-31 1 of 2 | ||
bad-project,20230613121411,2023-12-31,2,2,Entry 2023-12-31 2 of 2 | ||
bad-project,20230613121411,2024-01-01,1,1,Entry 2024-01-01 1 of 1 | ||
bad-project,20230613121411,2024-01-02,1,1,Entry 2024-01-02 1 of 1 | ||
bad-project,20240210161248,2023-12-31,1,2,Entry 2023-12-31 1 of 2 | ||
bad-project,20240210161248,2023-12-31,2,2,Entry 2023-12-31 2 of 2 | ||
bad-project,20240210161248,2024-01-01,1,1,Entry 2024-01-01 1 of 1 | ||
bad-project,20240210161248,2024-01-02,1,1,Entry 2024-01-02 1 of 1 |
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,5 +1,5 @@ | ||
{ | ||
"version": 20230613121411, | ||
"version": 20240210161248, | ||
"project_name": "default", | ||
"description": "Default project" | ||
} |