Skip to content

Commit

Permalink
fixup! fixup! fixup! Add migrations controller
Browse files Browse the repository at this point in the history
  • Loading branch information
VladislavSokov committed Jul 10, 2024
1 parent 33ca5c1 commit 3fdaea5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app/controllers/actual_db_schema/migrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ module ActualDbSchema
class MigrationsController < ActionController::Base
def index; end

def show
render file: "#{Rails.root}/public/404.html", layout: false, status: :not_found unless migration
end

private

helper_method def migrations
@migrations ||= ActualDbSchema::Migration.all
end

helper_method def migration
@migration ||= ActualDbSchema::Migration.find(params[:id], params[:database])
end
end
end
6 changes: 6 additions & 0 deletions app/views/actual_db_schema/migrations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<th>Name</th>
<th>Branch</th>
<th>Database</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
Expand All @@ -26,6 +27,11 @@
<td><%= migration[:name] %></td>
<td><%= migration[:branch] %></td>
<td><%= migration[:database] %></td>
<td>
<div class='button-container'>
<%= link_to '👁 Show', migration_path(id: migration[:version], database: migration[:database]), class: 'button' %>
</div>
</td>
</tr>
<% end %>
</tbody>
Expand Down
44 changes: 44 additions & 0 deletions app/views/actual_db_schema/migrations/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<title>Migration Details</title>
<%= stylesheet_link_tag 'actual_db_schema/styles', media: 'all' %>
</head>
<body>
<div>
<h2>Migration <%= migration[:name] %> Details</h2>
<table>
<tbody>
<tr>
<th>Status</th>
<td><%= migration[:status] %></td>
</tr>
<tr>
<th>Migration ID</th>
<td><%= migration[:version] %></td>
</tr>
<tr>
<th>Branch</th>
<td><%= migration[:branch] %></td>
</tr>
<tr>
<th>Database</th>
<td><%= migration[:database] %></td>
</tr>
<tr>
<th>Path</th>
<td><%= migration[:filename] %></td>
</tr>
</tbody>
</table>

<h3>Migration Code</h3>
<div>
<pre><%= File.read(migration[:filename]) %></pre>
</div>
<div class='button-container'>
<%= link_to '← Back', migrations_path, class: 'button' %>
</div>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

ActualDbSchema::Engine.routes.draw do
resources :migrations, only: %i[index]
resources :migrations, only: %i[index show]
resources :phantom_migrations, only: %i[index show] do
member do
post :rollback
Expand Down
2 changes: 1 addition & 1 deletion lib/actual_db_schema/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def build_migration_struct(status, migration)
end

def find_migration_in_context(context, version)
migration = context.phantom_migrations.detect { |m| m.version.to_s == version }
migration = context.migrations.detect { |m| m.version.to_s == version }
return unless migration

status = context.migrations_status.detect { |_s, v| v.to_s == version }&.first || "unknown"
Expand Down

0 comments on commit 3fdaea5

Please sign in to comment.