dsu 3.0.0.alpha.4 → 3.0.0.alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df8402b46bfcbdf4996acb620b0ffc1f95205c809f23b123a1ff90c2a038b216
4
- data.tar.gz: d0fdf8533b43d092ba4b1ab2354790db0932834efb008e078dbecd48dfeacdb9
3
+ metadata.gz: '035990c511959ebd7464d992ec83d57237e1a88c315eb45c56310696a31cc95d'
4
+ data.tar.gz: 2db1ee5a01298ed8ab7de5d73fce977963a98b04e7e7ba655f81df5b20aa97ac
5
5
  SHA512:
6
- metadata.gz: d9783afd9f2927cc311a35c5b94dcc44eb07724e4ea08b47f4bac9e25004cb8f4515698bbccc67051ab3ab65f59746f2e8c3381f3bc34d2eaa2bd9ad6b472a2c
7
- data.tar.gz: d2b83fce1c7a4a4ce2b084707204470c7c5739c5fdc6d83c993d9d1c613e757980302efbd08e476972d731b0e0fa3523e047fefd72daf2febc3992e8add96b1d
6
+ metadata.gz: d8967ff9cfee117383a0a4a9b0f1988af92e934b45a7fd424eec59f8294a406863e810c6dcf9e1d45e257a311b915d82dea8ee054a1bd90abb81c6971804881c
7
+ data.tar.gz: 8eb347d35a332b81f955c8c77c1ec5cc0f1c6bbb57afaa990e60a750c24d085c5d1b8f661957b48f17df1d629a4041eb444232cdc44b05fdc7b7ceadb798aed0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dsu (3.0.0.alpha.3)
4
+ dsu (3.0.0.alpha.4)
5
5
  activemodel (>= 7.0.8, < 8.0)
6
6
  activesupport (>= 7.0.8, < 8.0)
7
7
  colorize (>= 1.1, < 2.0)
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../models/migration_version'
4
+ require_relative 'service_20230613121411'
5
+ require_relative 'version'
6
+
7
+ module Dsu
8
+ module Migration
9
+ class Factory
10
+ class << self
11
+ def migrate_if!(options: {})
12
+ version = options.fetch(:version, migration_version)
13
+ if version == 20230613121411 # rubocop:disable Style/NumericLiterals
14
+ Service20230613121411.new(options: options).migrate!
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def migration_version
21
+ @migration_version ||= Models::MigrationVersion.new.version
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,171 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../support/fileable'
4
+ require_relative 'version'
5
+
6
+ # TODO: Read raw configuration .json file
7
+ # If default_project is not set...
8
+ # - Add default_project to configuration .json file and write it out.
9
+ # - Reload the configuration file.
10
+ # - Create a Models::Project object for the default project and initialize/save it.
11
+ # - Move the old entries folder into the default project folder.
12
+ # TODO: Add default_project to configuration .json file
13
+ module Dsu
14
+ module Migration
15
+ class Service20230613121411
16
+ include Support::Fileable
17
+
18
+ def initialize(options: {})
19
+ @options = options || {}
20
+ end
21
+
22
+ def migrate!
23
+ puts 'Running migrations...'
24
+ puts
25
+
26
+ puts "options[:pretend] is true\n" if pretend?
27
+
28
+ raise_wrong_migration_version_error_if!
29
+
30
+ puts "Migrating from: #{target_migration_version} to version: #{Migration::VERSION}"
31
+ puts
32
+
33
+ add_new_color_themes
34
+ backup
35
+ create_default_project
36
+ update_configuration
37
+ update_entry_groups
38
+ update_color_themes
39
+ delete_old_entry_folder
40
+ delete_old_theme_folder
41
+
42
+ puts 'Migration completed successfully.'
43
+ end
44
+
45
+ private
46
+
47
+ attr_reader :options
48
+
49
+ def pretend?
50
+ options.fetch(:pretend, true)
51
+ end
52
+
53
+ def add_new_color_themes
54
+ puts 'Copying new color themes...'
55
+ puts
56
+
57
+ %w[light.json christmas.json].each do |theme_file|
58
+ destination_theme_file_path = File.join(Dsu::Support::Fileable.themes_folder, theme_file)
59
+ next if File.exist?(destination_theme_file_path)
60
+
61
+ source_theme_file_path = File.join(Dsu::Support::Fileable.seed_data_folder, 'themes', theme_file)
62
+ FileUtils.cp(source_theme_file_path, destination_theme_file_path) unless pretend?
63
+ puts I18n.t('migrations.information.theme_copied', from: source_theme_file_path, to: destination_theme_file_path)
64
+ end
65
+ end
66
+
67
+ def backup
68
+ return if Dir.exist?(backup_folder)
69
+
70
+ puts 'Creating backup...'
71
+ puts
72
+
73
+ FileUtils.cp_r(dsu_folder, backup_folder) unless pretend?
74
+ end
75
+
76
+ def create_default_project
77
+ default_project = Models::Configuration::DEFAULT_CONFIGURATION[:default_project]
78
+ return if Models::Project.project_initialized?(project_name: default_project)
79
+
80
+ puts "Creating default project \"#{default_project}\"..."
81
+ puts
82
+
83
+ Models::Project.create(project_name: default_project, options: options) unless pretend?
84
+ end
85
+
86
+ def update_configuration
87
+ puts 'Updating configuration...'
88
+ puts
89
+
90
+ Models::Configuration.new.write! unless pretend?
91
+ end
92
+
93
+ def update_entry_groups
94
+ puts 'Updating entry groups...'
95
+ puts
96
+
97
+ return if Dir.exist?(entries_folder) || pretend?
98
+
99
+ puts 'Copying entries to default project...'
100
+ puts
101
+
102
+ FileUtils.mkdir_p(entries_folder)
103
+ FileUtils.cp_r(File.join(backup_folder, 'entries', '.'), entries_folder)
104
+
105
+ puts 'Updating entry group version...'
106
+ puts
107
+
108
+ Models::EntryGroup.all.each do |entry_group|
109
+ puts "Updating entry group version: #{entry_group.time_yyyy_mm_dd}..."
110
+ entry_group.version = Dsu::Migration::VERSION
111
+ entry_group.save! unless pretend?
112
+ end
113
+ end
114
+
115
+ def update_color_themes
116
+ puts 'Updating color themes...'
117
+ puts
118
+
119
+ return if Dir.exist?(themes_folder) || pretend?
120
+
121
+ puts 'Copying color themes...'
122
+ puts
123
+
124
+ FileUtils.mkdir_p(themes_folder)
125
+ FileUtils.cp_r(File.join(backup_folder, 'themes', '.'), themes_folder)
126
+
127
+ puts 'Updating color theme version...'
128
+ puts
129
+
130
+ Models::ColorTheme.all.each do |color_theme|
131
+ puts "Updating color theme version: #{color_theme.theme_name}..."
132
+ color_theme.version = Dsu::Migration::VERSION
133
+ color_theme.save! unless pretend?
134
+ end
135
+ end
136
+
137
+ def delete_old_entry_folder
138
+ puts 'Cleaning up old entries...'
139
+ puts
140
+
141
+ FileUtils.rm_rf(File.join(dsu_folder, 'entries')) unless pretend?
142
+ end
143
+
144
+ def delete_old_theme_folder
145
+ puts 'Cleaning up old themes...'
146
+ puts
147
+
148
+ FileUtils.rm_rf(File.join(dsu_folder, 'themes')) unless pretend?
149
+ end
150
+
151
+ def backup_folder
152
+ @backup_folder ||= File.join(dsu_folder, target_migration_version.to_s)
153
+ end
154
+
155
+ def target_migration_version
156
+ 20230613121411 # rubocop:disable Style/NumericLiterals
157
+ end
158
+
159
+ def raise_wrong_migration_version_error_if!
160
+ return if migration_version == target_migration_version
161
+
162
+ raise "Actual migration version #{migration_version} " \
163
+ "is not the expected migration version #{target_migration_version}."
164
+ end
165
+
166
+ def migration_version
167
+ @migration_version ||= Models::MigrationVersion.new.version
168
+ end
169
+ end
170
+ end
171
+ end
data/lib/dsu/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Dsu
4
4
  VERSION_REGEX = /\A\d+\.\d+\.\d+(\.(alpha|rc)\.\d+)?\z/
5
- VERSION = '3.0.0.alpha.4'
5
+ VERSION = '3.0.0.alpha.5'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsu
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.alpha.4
4
+ version: 3.0.0.alpha.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gene M. Angelo, Jr.
@@ -159,7 +159,6 @@ files:
159
159
  - bin/console
160
160
  - bin/dsu
161
161
  - bin/setup
162
- - current_project.bak
163
162
  - exe/dsu
164
163
  - lib/core/ruby/color_theme_colors.rb
165
164
  - lib/core/ruby/color_theme_mode.rb
@@ -170,7 +169,9 @@ files:
170
169
  - lib/dsu/command_services/add_entry_service.rb
171
170
  - lib/dsu/crud/json_file.rb
172
171
  - lib/dsu/env.rb
172
+ - lib/dsu/migration/factory.rb
173
173
  - lib/dsu/migration/service.rb
174
+ - lib/dsu/migration/service_20230613121411.rb
174
175
  - lib/dsu/migration/version.rb
175
176
  - lib/dsu/models/color_theme.rb
176
177
  - lib/dsu/models/configuration.rb
data/current_project.bak DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "version": 20240210161248,
3
- "project_name": "default"
4
- }