litestream_rails 0.2.0 → 0.4.0

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: 85ce722db144991b0abff9e4d561b97edf7d79511e58d9f7b5efe94745f5da64
4
- data.tar.gz: 377aee1ce72a27d28de8f1e5997a3220a4d5df001c584c7f6999d21fa996c491
3
+ metadata.gz: 07b007b5c9d51aa745ff55bee9692c8136b65ee58bd9ec7fe9268d1023a9f191
4
+ data.tar.gz: 6f87be36ebf727ae6ceba9da5568d213d1c147f358bac76d350875c442c64e8b
5
5
  SHA512:
6
- metadata.gz: cfb29875dfa4b5874b16f7fcb4dcb24eff02a9c1139db7c5ca69ffe1b3ce30755a6667ee06ed175695b045266c2bb21336f68a89c658bf09d4dcab9acfff2522
7
- data.tar.gz: b7876c11f1e3828322f33b6da2f4ba8ce9c6f444b6419e28621a07f2432f64b8141f04158216bac5d28a31e1badfe9e0d510facd8e350c07d98cc234e726012b
6
+ metadata.gz: 5100418dc719c6e28cf1e8e8ca238487167859541035a176845897773320a3c46c1eddd3c2cfb4a4dc2daee6e7674cce68f1acd9f84a9b9eb460ad8110b356aa
7
+ data.tar.gz: c52838111d8e0bce68c9b94843c48147c58b1ab11bb16f3b11ffb898f5dbad439812c722c16f8b6abce937ad76ec655c9890d8150c6e14cc816ee495a161f184
@@ -0,0 +1,17 @@
1
+ module LitestreamRails
2
+ class RestorationsController < ApplicationController
3
+ # POST /restorations
4
+ def create
5
+ database = params[:database].remove("[ROOT]/")
6
+ dir, file = File.split(database)
7
+ ext = File.extname(file)
8
+ base = File.basename(file, ext)
9
+ now = Time.now.utc.strftime("%Y%m%d%H%M%S")
10
+ backup = File.join(dir, "#{base}-#{now}#{ext}")
11
+
12
+ Litestream::Commands.restore(database, async: false, **{"-o" => backup})
13
+
14
+ redirect_to root_path, notice: "Restored to <code>#{backup}</code>."
15
+ end
16
+ end
17
+ end
@@ -544,6 +544,9 @@
544
544
  .inline-flex {
545
545
  display: inline-flex;
546
546
  }
547
+ .inline-block {
548
+ display: inline-block;
549
+ }
547
550
  .table {
548
551
  display: table;
549
552
  }
@@ -621,16 +624,35 @@
621
624
  .rounded-md {
622
625
  border-radius: 0.375rem;
623
626
  }
627
+ .rounded-lg {
628
+ border-radius: 0.5rem;
629
+ }
624
630
  .border-b {
625
631
  border-bottom-width: 1px;
626
632
  }
627
633
  .border-t {
628
634
  border-top-width: 1px;
629
635
  }
636
+ .bg-green-50 {
637
+ --tw-bg-opacity: 1;
638
+ background-color: rgb(240 253 244 / var(--tw-bg-opacity));
639
+ }
640
+ .bg-red-50 {
641
+ --tw-bg-opacity: 1;
642
+ background-color: rgb(254 242 242 / var(--tw-bg-opacity));
643
+ }
630
644
  .bg-green-100 {
631
645
  --tw-bg-opacity: 1;
632
646
  background-color: rgb(220 252 231 / var(--tw-bg-opacity));
633
647
  }
648
+ .bg-red-100 {
649
+ --tw-bg-opacity: 1;
650
+ background-color: rgb(254 226 226 / var(--tw-bg-opacity));
651
+ }
652
+ .bg-yellow-100 {
653
+ --tw-bg-opacity: 1;
654
+ background-color: rgb(254 249 195 / var(--tw-bg-opacity));
655
+ }
634
656
  .bg-slate-800 {
635
657
  --tw-bg-opacity: 1;
636
658
  background-color: rgb(30 41 59 / var(--tw-bg-opacity));
@@ -650,6 +672,10 @@
650
672
  padding-left: 0.625rem;
651
673
  padding-right: 0.625rem;
652
674
  }
675
+ .px-3 {
676
+ padding-left: 0.75rem;
677
+ padding-right: 0.75rem;
678
+ }
653
679
  .py-1 {
654
680
  padding-top: 0.25rem;
655
681
  padding-bottom: 0.25rem;
@@ -694,12 +720,23 @@
694
720
  font-size: 0.875rem;
695
721
  line-height: 1.25rem;
696
722
  }
723
+ .font-medium {
724
+ font-weight: 500;
725
+ }
697
726
  .font-bold {
698
727
  font-weight: 700;
699
728
  }
700
729
  .font-semibold {
701
730
  font-weight: 600;
702
731
  }
732
+ .text-green-500 {
733
+ --tw-text-opacity: 1;
734
+ color: rgb(34 197 94 / var(--tw-text-opacity));
735
+ }
736
+ .text-red-500 {
737
+ --tw-text-opacity: 1;
738
+ color: rgb(239 68 68 / var(--tw-text-opacity));
739
+ }
703
740
  .text-blue-500 {
704
741
  --tw-text-opacity: 1;
705
742
  color: rgb(59 130 246 / var(--tw-text-opacity));
@@ -712,6 +749,14 @@
712
749
  --tw-text-opacity: 1;
713
750
  color: rgb(22 101 52 / var(--tw-text-opacity));
714
751
  }
752
+ .text-red-800 {
753
+ --tw-text-opacity: 1;
754
+ color: rgb(153 27 27 / var(--tw-text-opacity));
755
+ }
756
+ .text-yellow-800 {
757
+ --tw-text-opacity: 1;
758
+ color: rgb(133 77 14 / var(--tw-text-opacity));
759
+ }
715
760
  .text-white {
716
761
  --tw-text-opacity: 1;
717
762
  color: rgb(255 255 255 / var(--tw-text-opacity));
@@ -24,7 +24,7 @@
24
24
  <p id="notice"
25
25
  class="py-2 px-3 bg-green-50 text-green-500 font-medium rounded-lg inline-block"
26
26
  data-controller="fade">
27
- <%= notice %>
27
+ <%= notice.html_safe %>
28
28
  </p>
29
29
  <% end %>
30
30
 
@@ -32,7 +32,7 @@
32
32
  <p id="alert"
33
33
  class="py-2 px-3 bg-red-50 text-red-500 font-medium rounded-lg inline-block"
34
34
  data-controller="fade">
35
- <%= alert %>
35
+ <%= alert.html_safe %>
36
36
  </p>
37
37
  <% end %>
38
38
  </div>
@@ -2,24 +2,39 @@
2
2
  <div class="flex items-center justify-between">
3
3
  <h1 class="flex items-baseline gap-2 text-2xl font-bold">
4
4
  Litestream
5
- <small class="inline-flex rounded-full bg-green-100 px-2 text-sm font-semibold text-green-800">
6
- <%= @process[:status] %>
7
- </small>
5
+
6
+ <% if @process[:status] == "sleeping" %>
7
+ <small class="inline-flex rounded-full px-2 text-sm font-semibold bg-yellow-100 text-yellow-800">
8
+ <%= @process[:status] %>
9
+ </small>
10
+ <% elsif @process[:status] %>
11
+ <small class="inline-flex rounded-full px-2 text-sm font-semibold bg-green-100 text-green-800">
12
+ <%= @process[:status] %>
13
+ </small>
14
+ <% else %>
15
+ <small class="inline-flex rounded-full px-2 text-sm font-semibold bg-red-100 text-red-800">
16
+ not running
17
+ </small>
18
+ <% end %>
8
19
  </h1>
9
20
 
10
- <small class="text-base">
11
- #<code><%= @process[:pid] %></code>
12
- </small>
21
+ <% if @process[:status] %>
22
+ <small class="text-base">
23
+ #<code><%= @process[:pid] %></code>
24
+ </small>
25
+ <% end %>
13
26
  </div>
14
27
 
15
- <dl class="grid grid-cols-[fit-content(100%)_1fr] gap-x-4">
16
- <dt class="font-bold">Started at</dt>
17
- <dd class="">
18
- <abbr title="<%= @process[:started] %>" class="underline decoration-dashed decoration-gray-500 cursor-help">
19
- <time datetime="<%= @process[:started] %>"><%= @process[:started].to_formatted_s(:db) %></time>
20
- </abbr>
21
- </dd>
22
- </dl>
28
+ <% if @process[:status] %>
29
+ <dl class="grid grid-cols-[fit-content(100%)_1fr] gap-x-4">
30
+ <dt class="font-bold">Started at</dt>
31
+ <dd class="">
32
+ <abbr title="<%= @process[:started] %>" class="underline decoration-dashed decoration-gray-500 cursor-help">
33
+ <time datetime="<%= @process[:started] %>"><%= @process[:started].to_formatted_s(:db) %></time>
34
+ </abbr>
35
+ </dd>
36
+ </dl>
37
+ <% end %>
23
38
  </section>
24
39
  <br>
25
40
  <br>
@@ -37,7 +52,7 @@
37
52
  <h2 class="text-lg font-bold">
38
53
  <code><%= database['path'] %></code>
39
54
  </h2>
40
- <button type="button" class="rounded-md bg-slate-800 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-slate-700">Restore</button>
55
+ <%= button_to "Restore", restorations_path, class: "rounded-md bg-slate-800 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-slate-700", params: { database: database['path'] } %>
41
56
  </div>
42
57
 
43
58
  <br />
data/config/routes.rb CHANGED
@@ -2,4 +2,5 @@ LitestreamRails::Engine.routes.draw do
2
2
  get "/" => "processes#show", :as => :root
3
3
 
4
4
  resource :process, only: [:show], path: ""
5
+ resources :restorations, only: [:create]
5
6
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LitestreamRails
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: litestream_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Margheim
@@ -91,6 +91,7 @@ files:
91
91
  - Rakefile
92
92
  - app/controllers/litestream_rails/application_controller.rb
93
93
  - app/controllers/litestream_rails/processes_controller.rb
94
+ - app/controllers/litestream_rails/restorations_controller.rb
94
95
  - app/views/layouts/litestream_rails/_style.html
95
96
  - app/views/layouts/litestream_rails/application.html.erb
96
97
  - app/views/litestream_rails/processes/show.html.erb