dsu 3.0.0.alpha.4 → 3.0.0.alpha.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df8402b46bfcbdf4996acb620b0ffc1f95205c809f23b123a1ff90c2a038b216
4
- data.tar.gz: d0fdf8533b43d092ba4b1ab2354790db0932834efb008e078dbecd48dfeacdb9
3
+ metadata.gz: f4efd9846d0594686163447d7452fdf2e943707f13e7f6377e0b08090721fc0a
4
+ data.tar.gz: 7063dfd1364021a623beed1aa2318c2536a88f7aca33af79a4915c49531ff1c4
5
5
  SHA512:
6
- metadata.gz: d9783afd9f2927cc311a35c5b94dcc44eb07724e4ea08b47f4bac9e25004cb8f4515698bbccc67051ab3ab65f59746f2e8c3381f3bc34d2eaa2bd9ad6b472a2c
7
- data.tar.gz: d2b83fce1c7a4a4ce2b084707204470c7c5739c5fdc6d83c993d9d1c613e757980302efbd08e476972d731b0e0fa3523e047fefd72daf2febc3992e8add96b1d
6
+ metadata.gz: f5700fc27f2def9e4f5e6172ddb24e112ddc08b33923041537b72e282cb8ac2b1908668bbd6bb17bc082a86d9c047df51c4171dfab088f5621bb1eb6fcf7f7e9
7
+ data.tar.gz: 6d32ae431fbcf5a17e05cb45e9b54364e754a4a9223aa7eda0e3f286b92d83dddb205aa5f68abb87714bce5c9da70aada072705c89300475bf592d31ff92cd32
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 pretend? || Dir.exist?(entries_folder)
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 pretend? || Dir.exist?(themes_folder)
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.6'
6
6
  end
data/lib/dsu.rb CHANGED
@@ -34,5 +34,5 @@ unless Dsu.env.test? || Dsu.env.development?
34
34
  end
35
35
  end
36
36
 
37
- Dsu::Migration::Factory.migrate_if!
37
+ Dsu::Migration::Factory.migrate_if!(options: { pretend: true })
38
38
  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.6
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
- }