migration-manager 1.0

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.
data/Gemfile.lock ADDED
@@ -0,0 +1,201 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ migration-manager (1.0)
5
+ rails (>= 6.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (7.1.5.1)
11
+ actionpack (= 7.1.5.1)
12
+ activesupport (= 7.1.5.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ zeitwerk (~> 2.6)
16
+ actionmailbox (7.1.5.1)
17
+ actionpack (= 7.1.5.1)
18
+ activejob (= 7.1.5.1)
19
+ activerecord (= 7.1.5.1)
20
+ activestorage (= 7.1.5.1)
21
+ activesupport (= 7.1.5.1)
22
+ mail (>= 2.7.1)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.1.5.1)
27
+ actionpack (= 7.1.5.1)
28
+ actionview (= 7.1.5.1)
29
+ activejob (= 7.1.5.1)
30
+ activesupport (= 7.1.5.1)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
35
+ rails-dom-testing (~> 2.2)
36
+ actionpack (7.1.5.1)
37
+ actionview (= 7.1.5.1)
38
+ activesupport (= 7.1.5.1)
39
+ nokogiri (>= 1.8.5)
40
+ racc
41
+ rack (>= 2.2.4)
42
+ rack-session (>= 1.0.1)
43
+ rack-test (>= 0.6.3)
44
+ rails-dom-testing (~> 2.2)
45
+ rails-html-sanitizer (~> 1.6)
46
+ actiontext (7.1.5.1)
47
+ actionpack (= 7.1.5.1)
48
+ activerecord (= 7.1.5.1)
49
+ activestorage (= 7.1.5.1)
50
+ activesupport (= 7.1.5.1)
51
+ globalid (>= 0.6.0)
52
+ nokogiri (>= 1.8.5)
53
+ actionview (7.1.5.1)
54
+ activesupport (= 7.1.5.1)
55
+ builder (~> 3.1)
56
+ erubi (~> 1.11)
57
+ rails-dom-testing (~> 2.2)
58
+ rails-html-sanitizer (~> 1.6)
59
+ activejob (7.1.5.1)
60
+ activesupport (= 7.1.5.1)
61
+ globalid (>= 0.3.6)
62
+ activemodel (7.1.5.1)
63
+ activesupport (= 7.1.5.1)
64
+ activerecord (7.1.5.1)
65
+ activemodel (= 7.1.5.1)
66
+ activesupport (= 7.1.5.1)
67
+ timeout (>= 0.4.0)
68
+ activestorage (7.1.5.1)
69
+ actionpack (= 7.1.5.1)
70
+ activejob (= 7.1.5.1)
71
+ activerecord (= 7.1.5.1)
72
+ activesupport (= 7.1.5.1)
73
+ marcel (~> 1.0)
74
+ activesupport (7.1.5.1)
75
+ base64
76
+ benchmark (>= 0.3)
77
+ bigdecimal
78
+ concurrent-ruby (~> 1.0, >= 1.0.2)
79
+ connection_pool (>= 2.2.5)
80
+ drb
81
+ i18n (>= 1.6, < 2)
82
+ logger (>= 1.4.2)
83
+ minitest (>= 5.1)
84
+ mutex_m
85
+ securerandom (>= 0.3)
86
+ tzinfo (~> 2.0)
87
+ base64 (0.2.0)
88
+ benchmark (0.4.0)
89
+ bigdecimal (3.1.9)
90
+ builder (3.3.0)
91
+ concurrent-ruby (1.3.5)
92
+ connection_pool (2.5.0)
93
+ crass (1.0.6)
94
+ date (3.4.1)
95
+ drb (2.2.1)
96
+ erubi (1.13.1)
97
+ globalid (1.2.1)
98
+ activesupport (>= 6.1)
99
+ i18n (1.14.7)
100
+ concurrent-ruby (~> 1.0)
101
+ io-console (0.8.0)
102
+ irb (1.15.1)
103
+ pp (>= 0.6.0)
104
+ rdoc (>= 4.0.0)
105
+ reline (>= 0.4.2)
106
+ logger (1.6.6)
107
+ loofah (2.24.0)
108
+ crass (~> 1.0.2)
109
+ nokogiri (>= 1.12.0)
110
+ mail (2.8.1)
111
+ mini_mime (>= 0.1.1)
112
+ net-imap
113
+ net-pop
114
+ net-smtp
115
+ marcel (1.0.4)
116
+ mini_mime (1.1.5)
117
+ minitest (5.25.4)
118
+ mutex_m (0.3.0)
119
+ net-imap (0.4.19)
120
+ date
121
+ net-protocol
122
+ net-pop (0.1.2)
123
+ net-protocol
124
+ net-protocol (0.2.2)
125
+ timeout
126
+ net-smtp (0.5.1)
127
+ net-protocol
128
+ nio4r (2.7.4)
129
+ nokogiri (1.15.7-arm64-darwin)
130
+ racc (~> 1.4)
131
+ pp (0.6.2)
132
+ prettyprint
133
+ prettyprint (0.2.0)
134
+ psych (5.2.3)
135
+ date
136
+ stringio
137
+ racc (1.8.1)
138
+ rack (3.1.10)
139
+ rack-session (2.1.0)
140
+ base64 (>= 0.1.0)
141
+ rack (>= 3.0.0)
142
+ rack-test (2.2.0)
143
+ rack (>= 1.3)
144
+ rackup (2.2.1)
145
+ rack (>= 3)
146
+ rails (7.1.5.1)
147
+ actioncable (= 7.1.5.1)
148
+ actionmailbox (= 7.1.5.1)
149
+ actionmailer (= 7.1.5.1)
150
+ actionpack (= 7.1.5.1)
151
+ actiontext (= 7.1.5.1)
152
+ actionview (= 7.1.5.1)
153
+ activejob (= 7.1.5.1)
154
+ activemodel (= 7.1.5.1)
155
+ activerecord (= 7.1.5.1)
156
+ activestorage (= 7.1.5.1)
157
+ activesupport (= 7.1.5.1)
158
+ bundler (>= 1.15.0)
159
+ railties (= 7.1.5.1)
160
+ rails-dom-testing (2.2.0)
161
+ activesupport (>= 5.0.0)
162
+ minitest
163
+ nokogiri (>= 1.6)
164
+ rails-html-sanitizer (1.6.2)
165
+ loofah (~> 2.21)
166
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
167
+ railties (7.1.5.1)
168
+ actionpack (= 7.1.5.1)
169
+ activesupport (= 7.1.5.1)
170
+ irb
171
+ rackup (>= 1.0.0)
172
+ rake (>= 12.2)
173
+ thor (~> 1.0, >= 1.2.2)
174
+ zeitwerk (~> 2.6)
175
+ rake (12.3.3)
176
+ rdoc (6.12.0)
177
+ psych (>= 4.0.0)
178
+ reline (0.6.0)
179
+ io-console (~> 0.5)
180
+ securerandom (0.3.2)
181
+ stringio (3.1.3)
182
+ thor (1.3.2)
183
+ timeout (0.4.3)
184
+ tzinfo (2.0.6)
185
+ concurrent-ruby (~> 1.0)
186
+ websocket-driver (0.7.7)
187
+ base64
188
+ websocket-extensions (>= 0.1.0)
189
+ websocket-extensions (0.1.5)
190
+ zeitwerk (2.6.18)
191
+
192
+ PLATFORMS
193
+ ruby
194
+
195
+ DEPENDENCIES
196
+ migration-manager!
197
+ minitest (~> 5.0)
198
+ rake (~> 12.0)
199
+
200
+ BUNDLED WITH
201
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 rajnishmishra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Migration::Manager
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/migration/manager`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'migration-manager'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install migration-manager
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/migration-manager. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/migration-manager/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Migration::Manager project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/migration-manager/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,2 @@
1
+ //= link migration_manager.css
2
+ //= link migration_manager.js
@@ -0,0 +1,15 @@
1
+ document.addEventListener("DOMContentLoaded", function() {
2
+ const operationSelect = document.getElementById("operation_type");
3
+ const tableNameField = document.getElementById("table_name_field");
4
+
5
+ function toggleTableNameVisibility() {
6
+ if (operationSelect.value === "Create Table") {
7
+ tableNameField.style.display = "none";
8
+ } else {
9
+ tableNameField.style.display = "block";
10
+ }
11
+ }
12
+
13
+ operationSelect.addEventListener("change", toggleTableNameVisibility);
14
+ toggleTableNameVisibility(); // Initial check on page load
15
+ });
@@ -0,0 +1,43 @@
1
+ /* Custom styles for Migration Manager */
2
+ .form-container {
3
+ max-width: 600px;
4
+ margin: 20px auto;
5
+ padding: 20px;
6
+ background: #f8f9fa;
7
+ border-radius: 8px;
8
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
9
+ }
10
+
11
+ .form-group {
12
+ margin-bottom: 15px;
13
+ }
14
+
15
+ .form-label {
16
+ font-weight: bold;
17
+ display: block;
18
+ margin-bottom: 5px;
19
+ }
20
+
21
+ .form-input, .form-select {
22
+ width: 100%;
23
+ padding: 8px;
24
+ border: 1px solid #ced4da;
25
+ border-radius: 5px;
26
+ }
27
+
28
+ .hidden {
29
+ display: none;
30
+ }
31
+
32
+ .form-button {
33
+ background-color: #007bff;
34
+ color: white;
35
+ padding: 10px 15px;
36
+ border: none;
37
+ border-radius: 5px;
38
+ cursor: pointer;
39
+ }
40
+
41
+ .form-button:hover {
42
+ background-color: #0056b3;
43
+ }
@@ -0,0 +1,13 @@
1
+ module MigrationManager
2
+ class ApplicationController < ActionController::Base
3
+ before_action :authenticate_user
4
+
5
+ private
6
+
7
+ def authenticate_user
8
+ authenticate_or_request_with_http_basic do |user, password|
9
+ user == ENV['MIGRATION_MANAGER_USER'] && password == ENV['MIGRATION_MANAGER_PASSWORD']
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module MigrationManager
2
+ class HomeController < MigrationManager::ApplicationController
3
+ def index
4
+ # Get all migrations and their statuses
5
+ @migrations = ActiveRecord::Base.connection.execute(
6
+ "SELECT version FROM schema_migrations"
7
+ ).map { |row| row["version"] }.sort.reverse # Sort DESC
8
+
9
+ @all_migrations = ActiveRecord::Migrator.migrations_paths.flat_map do |path|
10
+ ActiveRecord::MigrationContext.new(path).migrations
11
+ end.sort_by(&:version).reverse
12
+
13
+ @pending_migrations = @all_migrations.reject { |m| @migrations.include?(m.version.to_s) }
14
+
15
+ @success_message = params[:success] if params[:success].present?
16
+ end
17
+
18
+ def run_migration
19
+ version = params[:version]
20
+
21
+ if version.present?
22
+ ActiveRecord::Migrator.run(:up, ActiveRecord::Migrator.migrations_paths, version.to_i)
23
+ redirect_to "#{request.base_url}/migration_manager/home", notice: "Migration #{version} successfully run.!"
24
+ else
25
+ redirect_to "#{request.base_url}/migration_manager/home", alert: "Invalid migration version."
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,58 @@
1
+ module MigrationManager
2
+ class MigrationBuilderController < MigrationManager::ApplicationController
3
+ def new
4
+ @tables = ActiveRecord::Base.connection.tables.reject { |t| t == 'schema_migrations' }
5
+ end
6
+
7
+ def create
8
+ migration_name = params[:migration_name].presence || "custom_migration"
9
+ operation = params[:operation] # "create_table" or "alter_table"
10
+ table_name = params[:table_name].presence
11
+ columns = params[:columns] || []
12
+
13
+ file_name = "#{Time.now.strftime('%Y%m%d%H%M%S')}_#{migration_name.underscore}.rb"
14
+ file_path = Rails.root.join("db/migrate/#{file_name}")
15
+
16
+ migration_content = generate_migration_content(migration_name, operation, table_name, columns)
17
+
18
+ File.open(file_path, "w") { |file| file.write(migration_content) }
19
+
20
+ redirect_to "#{request.base_url}/migration_manager/home", notice: "Migration #{file_name} created successfully!"
21
+ end
22
+
23
+ private
24
+
25
+ def generate_migration_content(name, operation, table, columns)
26
+ <<~RUBY
27
+ class #{name.camelize} < ActiveRecord::Migration[7.0]
28
+ def change
29
+ #{operation == "Create Table" ? create_table_code(table, columns) : alter_table_code(table, columns)}
30
+ end
31
+ end
32
+ RUBY
33
+ end
34
+
35
+ def create_table_code(table, columns)
36
+ col_definitions = columns.map do |col|
37
+ " t.#{col[:type]} :#{col[:name]}#{default_value(col[:default])}"
38
+ end.join("\n")
39
+
40
+ <<~RUBY
41
+ create_table :#{table} do |t|
42
+ #{col_definitions}
43
+ t.timestamps
44
+ end
45
+ RUBY
46
+ end
47
+
48
+ def alter_table_code(table, columns)
49
+ columns.map do |col|
50
+ " add_column :#{table}, :#{col[:name]}, :#{col[:type]}#{default_value(col[:default])}"
51
+ end.join("\n")
52
+ end
53
+
54
+ def default_value(value)
55
+ value.present? ? ", default: #{value.inspect}" : ""
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,131 @@
1
+ <div class="status-container">
2
+ <h1 class="status-title">Migration Status</h1>
3
+
4
+ <div class="button-container">
5
+ <a href="<%= migration_manager.new_migration_path %>" class="nav-button">Create / Modify Migration</a>
6
+ </div>
7
+
8
+ <% if @success_message %>
9
+ <p class="success-message"><%= @success_message %></p>
10
+ <% end %>
11
+
12
+ <table class="status-table">
13
+ <thead>
14
+ <tr>
15
+ <th>Version</th>
16
+ <th>Name</th>
17
+ <th>Status</th>
18
+ <th>Action</th>
19
+ </tr>
20
+ </thead>
21
+ <tbody>
22
+ <% @all_migrations.each do |migration| %>
23
+ <tr>
24
+ <td><%= migration.version %></td>
25
+ <td><%= migration.name %></td>
26
+ <td>
27
+ <% if @migrations.include?(migration.version.to_s) %>
28
+ <span class="status-migrated">Migrated</span>
29
+ <% else %>
30
+ <span class="status-pending">Pending</span>
31
+ <% end %>
32
+ </td>
33
+ <td>
34
+ <% unless @migrations.include?(migration.version.to_s) %>
35
+ <form action="<%= migration_manager.run_migration_path %>" method="post">
36
+ <input type="hidden" name="version" value="<%= migration.version %>">
37
+ <button type="submit" class="migrate-button">Migrate</button>
38
+ </form>
39
+ <% else %>
40
+
41
+ <% end %>
42
+ </td>
43
+ </tr>
44
+ <% end %>
45
+ </tbody>
46
+ </table>
47
+ </div>
48
+
49
+ <style>
50
+ /* Migration Status Styles */
51
+ .status-container {
52
+ max-width: 800px;
53
+ margin: 20px auto;
54
+ padding: 20px;
55
+ background: #f8f9fa;
56
+ border-radius: 8px;
57
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
58
+ }
59
+
60
+ .status-title {
61
+ text-align: center;
62
+ margin-bottom: 20px;
63
+ }
64
+
65
+ .button-container {
66
+ text-align: right;
67
+ margin-bottom: 15px;
68
+ }
69
+
70
+ .nav-button {
71
+ display: inline-block;
72
+ background-color: #007bff;
73
+ color: white;
74
+ padding: 8px 15px;
75
+ border-radius: 5px;
76
+ text-decoration: none;
77
+ font-weight: bold;
78
+ transition: background 0.3s;
79
+ }
80
+
81
+ .nav-button:hover {
82
+ background-color: #0056b3;
83
+ }
84
+
85
+ .success-message {
86
+ color: green;
87
+ font-weight: bold;
88
+ text-align: center;
89
+ margin-bottom: 10px;
90
+ }
91
+
92
+ .status-table {
93
+ width: 100%;
94
+ border-collapse: collapse;
95
+ background: white;
96
+ }
97
+
98
+ .status-table th, .status-table td {
99
+ border: 1px solid #dee2e6;
100
+ padding: 10px;
101
+ text-align: left;
102
+ }
103
+
104
+ .status-table th {
105
+ background: #007bff;
106
+ color: white;
107
+ }
108
+
109
+ .status-migrated {
110
+ color: green;
111
+ font-weight: bold;
112
+ }
113
+
114
+ .status-pending {
115
+ color: red;
116
+ font-weight: bold;
117
+ }
118
+
119
+ .migrate-button {
120
+ background-color: #28a745;
121
+ color: white;
122
+ padding: 6px 12px;
123
+ border: none;
124
+ border-radius: 4px;
125
+ cursor: pointer;
126
+ }
127
+
128
+ .migrate-button:hover {
129
+ background-color: #218838;
130
+ }
131
+ </style>