Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a web view for the Litestream replication process #29

Merged
merged 4 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/controllers/litestream/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Litestream
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
around_action :force_english_locale!

http_basic_authenticate_with name: Litestream.username, password: Litestream.password if Litestream.password

private

def force_english_locale!(&action)
I18n.with_locale(:en, &action)
end
end
end
9 changes: 9 additions & 0 deletions app/controllers/litestream/processes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Litestream
class ProcessesController < ApplicationController
# GET /process
def show
@process = Litestream.replicate_process
@databases = Litestream.databases
end
end
end
17 changes: 17 additions & 0 deletions app/controllers/litestream/restorations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Litestream
class RestorationsController < ApplicationController
# POST /restorations
def create
database = params[:database].remove("[ROOT]/")
dir, file = File.split(database)
ext = File.extname(file)
base = File.basename(file, ext)
now = Time.now.utc.strftime("%Y%m%d%H%M%S")
backup = File.join(dir, "#{base}-#{now}#{ext}")

Litestream::Commands.restore(database, async: false, **{"-o" => backup})

redirect_to root_path, notice: "Restored to <code>#{backup}</code>."
end
end
end
Loading
Loading