captive-cli 1.10.0 → 1.11.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.
- checksums.yaml +4 -4
- data/lib/captive/commands/addons_commands.rb +17 -0
- data/lib/captive/commands/db_commands.rb +22 -0
- data/lib/captive/commands/db_migrations_mark.rb +54 -0
- data/lib/captive/commands/pg_cron_change.rb +24 -0
- data/lib/captive/dashboard/addons_resource.rb +4 -0
- data/lib/captive/loader.rb +1 -0
- data/lib/captive/presenter/pg_cron.rb +34 -0
- data/lib/captive/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 72b1622689b08b0eef85aaade0d3a87567f623798659fea71c2a2db35c8f2a3a
|
|
4
|
+
data.tar.gz: 8835974c91d69d4075d615499063887d2cd2cc2117bd960bdf199174fcc9626f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d701686536a48fcbc4037d3db660e087894e02cb98ebb1c6435c107807a4aa008cb1194c28182747d25347ebeacf548e832b4d7b3098ba1f8206711c72f15b77
|
|
7
|
+
data.tar.gz: 65a0b1ce4eb77dab427a559e3c220b81c1d33c7b82c7220370bd1621be29f5781c5c819b4c56e8ac3d9f56af558b1e84206ac930d69040bc0929ad809709dfdf
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "supabase_auth_change"
|
|
4
4
|
require_relative "supabase_realtime_change"
|
|
5
|
+
require_relative "pg_cron_change"
|
|
5
6
|
|
|
6
7
|
module Captive
|
|
7
8
|
module Commands
|
|
@@ -83,6 +84,22 @@ module Captive
|
|
|
83
84
|
puts SupabaseRealtimeChange.new(addons: addons_api, paint: paint).run(app, options)
|
|
84
85
|
end
|
|
85
86
|
|
|
87
|
+
desc "pg-cron APP", "Affiche ou modifie l'option pg_cron et pg_net de la base"
|
|
88
|
+
long_desc <<~DESC
|
|
89
|
+
Sans option : affiche si pg_cron et pg_net sont activés sur la base.
|
|
90
|
+
Avec --enabled : les active ou les désactive. La base redémarre.
|
|
91
|
+
Exige PostgreSQL 18. Réservé aux admins de l'Organization.
|
|
92
|
+
|
|
93
|
+
\x05Exemples :
|
|
94
|
+
\x05 captive addons pg-cron my-app-staging
|
|
95
|
+
\x05 captive addons pg-cron my-app-staging --enabled=true
|
|
96
|
+
DESC
|
|
97
|
+
method_option :enabled, enum: %w[true false], desc: "Option pg_cron et pg_net"
|
|
98
|
+
map "pg-cron" => :pg_cron
|
|
99
|
+
def pg_cron(app)
|
|
100
|
+
puts PgCronChange.new(addons: addons_api, paint: paint).run(app, options)
|
|
101
|
+
end
|
|
102
|
+
|
|
86
103
|
private
|
|
87
104
|
|
|
88
105
|
def presenter = Presenter::Addon.new(paint: paint)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require "tty-spinner"
|
|
4
4
|
require_relative "db_exec"
|
|
5
5
|
require_relative "db_psql"
|
|
6
|
+
require_relative "db_migrations_mark"
|
|
6
7
|
|
|
7
8
|
module Captive
|
|
8
9
|
module Commands
|
|
@@ -49,6 +50,27 @@ module Captive
|
|
|
49
50
|
abort paint.red("✗ #{e.message}")
|
|
50
51
|
end
|
|
51
52
|
|
|
53
|
+
desc "migrations-mark APP", "Inscrit les migrations Supabase comme jouées, sans les jouer"
|
|
54
|
+
long_desc <<~DESC
|
|
55
|
+
Pour une base migrée à la main avant que la plateforme joue les migrations au
|
|
56
|
+
déploiement : inscrit chaque fichier <horodatage>_<nom>.sql du dossier dans
|
|
57
|
+
supabase_migrations.schema_migrations, sans l'exécuter. Une version déjà inscrite
|
|
58
|
+
est laissée telle quelle. --up-to s'arrête à la dernière migration réellement jouée.
|
|
59
|
+
|
|
60
|
+
\x05Exemple :
|
|
61
|
+
\x05 captive db migrations-mark sas-seatup-staging
|
|
62
|
+
\x05 captive db migrations-mark sas-seatup-staging --up-to 20261020120000
|
|
63
|
+
DESC
|
|
64
|
+
method_option :dir, type: :string, default: "supabase/migrations", desc: "Dossier des migrations"
|
|
65
|
+
method_option :up_to, type: :string, desc: "Dernière version à inscrire (incluse)"
|
|
66
|
+
def migrations_mark(app)
|
|
67
|
+
versions = DbMigrationsMark.new(exec: DbExec.new(kubectl: kubectl, trail: trail))
|
|
68
|
+
.run(app, options[:dir], up_to: options[:up_to])
|
|
69
|
+
puts paint.green(" ✓ #{versions.size} migrations inscrites comme jouées, jusqu'à #{versions.last}.")
|
|
70
|
+
rescue Captive::ExecError => e
|
|
71
|
+
abort paint.red("✗ #{e.message}")
|
|
72
|
+
end
|
|
73
|
+
|
|
52
74
|
desc "psql APP", "Ouvre une session psql sur la base, ou joue une requête avec -c"
|
|
53
75
|
long_desc <<~DESC
|
|
54
76
|
Session psql interactive sur la base de l'app, sous un rôle admin
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "tempfile"
|
|
4
|
+
require_relative "../errors"
|
|
5
|
+
|
|
6
|
+
module Captive
|
|
7
|
+
module Commands
|
|
8
|
+
# Inscrit les migrations d'un dossier local dans supabase_migrations.schema_migrations sans
|
|
9
|
+
# les jouer : la base a été migrée à la main (captive db exec), l'initContainer de
|
|
10
|
+
# déploiement (BRIO-268) rejouerait tout sur une table de suivi vide. L'équivalent de
|
|
11
|
+
# `supabase migration repair --status applied`, joué via captive db exec.
|
|
12
|
+
class DbMigrationsMark
|
|
13
|
+
FILE = /\A([0-9]+)_(.*)\.sql\z/
|
|
14
|
+
|
|
15
|
+
# La table du CLI Supabase (supabase/cli, pkg/migration/history.go).
|
|
16
|
+
TABLE = <<~SQL
|
|
17
|
+
create schema if not exists supabase_migrations;
|
|
18
|
+
create table if not exists supabase_migrations.schema_migrations (version text not null primary key);
|
|
19
|
+
alter table supabase_migrations.schema_migrations add column if not exists statements text[];
|
|
20
|
+
alter table supabase_migrations.schema_migrations add column if not exists name text;
|
|
21
|
+
SQL
|
|
22
|
+
|
|
23
|
+
def initialize(exec:)
|
|
24
|
+
@exec = exec
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def run(app, dir, up_to: nil)
|
|
28
|
+
migrations = read(dir).select { |version, _| up_to.nil? || version.to_i <= up_to.to_i }
|
|
29
|
+
raise ExecError, "aucune migration <horodatage>_<nom>.sql dans #{dir}" if migrations.empty?
|
|
30
|
+
|
|
31
|
+
Tempfile.create([ "marquage", ".sql" ]) do |file|
|
|
32
|
+
file.write(TABLE + inscription(migrations))
|
|
33
|
+
file.close
|
|
34
|
+
@exec.run(app, file.path)
|
|
35
|
+
end
|
|
36
|
+
migrations.map(&:first)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def read(dir)
|
|
42
|
+
Dir.children(dir).sort.filter_map { |name| FILE.match(name)&.captures }
|
|
43
|
+
rescue Errno::ENOENT
|
|
44
|
+
[]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def inscription(migrations)
|
|
48
|
+
values = migrations.map { |version, name| "('#{version}', '#{name.gsub("'", "''")}')" }
|
|
49
|
+
"insert into supabase_migrations.schema_migrations (version, name) values\n " \
|
|
50
|
+
"#{values.join(",\n ")}\non conflict (version) do nothing;\n"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Captive
|
|
4
|
+
module Commands
|
|
5
|
+
# `addons pg-cron` : sans réglage, les lignes qui décrivent l'option ; avec --enabled, l'état
|
|
6
|
+
# voulu envoyé au dashboard, que captive-platform applique plus tard en redémarrant la base (ADR 0041).
|
|
7
|
+
class PgCronChange
|
|
8
|
+
def initialize(addons:, paint:)
|
|
9
|
+
@addons = addons
|
|
10
|
+
@paint = paint
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# `options` : les options Thor de la commande, `enabled` ("true"/"false").
|
|
14
|
+
def run(app, options)
|
|
15
|
+
enabled = options["enabled"]
|
|
16
|
+
return Presenter::PgCron.new(paint: @paint).lines(@addons.pg_cron(app), app: app) unless enabled
|
|
17
|
+
|
|
18
|
+
@addons.set_pg_cron(app, enabled: enabled == "true")
|
|
19
|
+
[ @paint.green(" ✓ Option pg_cron en cours de modification, la base redémarre : #{CLIDependencies::ASYNC_NOTICE}"),
|
|
20
|
+
@paint.dim(" Suivre : captive addons pg-cron #{app}"), ]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -8,6 +8,7 @@ module Captive
|
|
|
8
8
|
PATH = AppPath.new("addons")
|
|
9
9
|
SUPABASE_AUTH_PATH = AppPath.new("addons/supabase/auth")
|
|
10
10
|
SUPABASE_REALTIME_PATH = AppPath.new("addons/supabase/realtime")
|
|
11
|
+
PG_CRON_PATH = AppPath.new("addons/supabase/pg-cron")
|
|
11
12
|
|
|
12
13
|
def initialize(api:)
|
|
13
14
|
@api = api
|
|
@@ -28,6 +29,9 @@ module Captive
|
|
|
28
29
|
def set_supabase_realtime(app, enabled:, postgres_changes:)
|
|
29
30
|
@api.put(SUPABASE_REALTIME_PATH.call(app), { enabled: enabled, postgres_changes: postgres_changes })
|
|
30
31
|
end
|
|
32
|
+
|
|
33
|
+
def pg_cron(app) = @api.get(PG_CRON_PATH.call(app))
|
|
34
|
+
def set_pg_cron(app, enabled:) = @api.put(PG_CRON_PATH.call(app), { enabled: enabled })
|
|
31
35
|
end
|
|
32
36
|
end
|
|
33
37
|
end
|
data/lib/captive/loader.rb
CHANGED
|
@@ -26,6 +26,7 @@ require_relative "presenter/domain"
|
|
|
26
26
|
require_relative "presenter/addon"
|
|
27
27
|
require_relative "presenter/supabase_auth"
|
|
28
28
|
require_relative "presenter/supabase_realtime"
|
|
29
|
+
require_relative "presenter/pg_cron"
|
|
29
30
|
require_relative "presenter/edge_function"
|
|
30
31
|
require_relative "activity_trail"
|
|
31
32
|
require_relative "errors"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Captive
|
|
4
|
+
module Presenter
|
|
5
|
+
# L'option pg_cron et pg_net de la base, comme sur la page pg_cron du dashboard (ADR 0041).
|
|
6
|
+
class PgCron
|
|
7
|
+
VALEURS = { true => "oui", false => "non" }.freeze
|
|
8
|
+
|
|
9
|
+
def initialize(paint:)
|
|
10
|
+
@paint = paint
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def lines(settings, app:)
|
|
14
|
+
[
|
|
15
|
+
[ "pg_cron et pg_net #{VALEURS.fetch(settings["enabled"], "inconnu")}", indisponible(settings) ].compact.join(" "),
|
|
16
|
+
(@paint.yellow("Changement en cours…") if settings["pending"]),
|
|
17
|
+
@paint.dim(modification(settings, app)),
|
|
18
|
+
].compact
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def modification(settings, app)
|
|
24
|
+
return "Modifiable par un admin de l'Organization" unless settings["can_edit"]
|
|
25
|
+
|
|
26
|
+
"Modifier : captive addons pg-cron #{app} --enabled=true|false (redémarre la base)"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def indisponible(settings)
|
|
30
|
+
@paint.dim("(PostgreSQL 18 requis)") if settings["available"] == false
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/captive/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: captive-cli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Captive Studio
|
|
@@ -118,6 +118,7 @@ files:
|
|
|
118
118
|
- lib/captive/commands/db_commands.rb
|
|
119
119
|
- lib/captive/commands/db_dump.rb
|
|
120
120
|
- lib/captive/commands/db_exec.rb
|
|
121
|
+
- lib/captive/commands/db_migrations_mark.rb
|
|
121
122
|
- lib/captive/commands/db_psql.rb
|
|
122
123
|
- lib/captive/commands/db_target.rb
|
|
123
124
|
- lib/captive/commands/domain_announcer.rb
|
|
@@ -128,6 +129,7 @@ files:
|
|
|
128
129
|
- lib/captive/commands/functions_commands.rb
|
|
129
130
|
- lib/captive/commands/logs.rb
|
|
130
131
|
- lib/captive/commands/one_off_session.rb
|
|
132
|
+
- lib/captive/commands/pg_cron_change.rb
|
|
131
133
|
- lib/captive/commands/run.rb
|
|
132
134
|
- lib/captive/commands/supabase_auth_change.rb
|
|
133
135
|
- lib/captive/commands/supabase_commands.rb
|
|
@@ -161,6 +163,7 @@ files:
|
|
|
161
163
|
- lib/captive/presenter/domain.rb
|
|
162
164
|
- lib/captive/presenter/edge_function.rb
|
|
163
165
|
- lib/captive/presenter/log_colorizer.rb
|
|
166
|
+
- lib/captive/presenter/pg_cron.rb
|
|
164
167
|
- lib/captive/presenter/scheduled_task.rb
|
|
165
168
|
- lib/captive/presenter/supabase_auth.rb
|
|
166
169
|
- lib/captive/presenter/supabase_realtime.rb
|