create-expo-updates-server 0.1.3 → 0.1.5
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.
- package/dist/template/.env.docker.example +1 -0
- package/dist/template/.env.example +2 -0
- package/dist/template/README.md +16 -8
- package/dist/template/app/api/admin/distribution-control/route.test.ts +153 -0
- package/dist/template/app/api/admin/distribution-control/route.ts +111 -0
- package/dist/template/app/api/admin/embedded-updates/route.test.ts +36 -1
- package/dist/template/app/api/admin/guard-actions/[id]/route.test.ts +60 -0
- package/dist/template/app/api/admin/guard-actions/[id]/route.ts +32 -0
- package/dist/template/app/api/admin/guard-actions/route.test.ts +123 -0
- package/dist/template/app/api/admin/guard-actions/route.ts +66 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +4 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/policy/route.test.ts +171 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/policy/route.ts +75 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +4 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +4 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +4 -1
- package/dist/template/app/api/admin/updates/route.test.ts +29 -1
- package/dist/template/app/updates/[encodedKey]/page.tsx +74 -6
- package/dist/template/app/updates/embedded/page.tsx +6 -2
- package/dist/template/app/updates/page.tsx +28 -3
- package/dist/template/docs/expo-app-setup.md +14 -3
- package/dist/template/docs/getting-started.md +13 -7
- package/dist/template/docs/getting-started.ru.md +15 -7
- package/dist/template/docs/migrations/2026-09-01-app-version-columns.sql +23 -0
- package/dist/template/docs/migrations/2026-09-01-ota-update-policy.sql +108 -0
- package/dist/template/docs/migrations/2026-09-01-p1-guard-actions.sql +19 -0
- package/dist/template/docs/migrations/2026-09-01-p2-simplify-ota-guard-policy.sql +69 -0
- package/dist/template/docs/migrations/2026-09-01-policy-publication-correction.sql +44 -0
- package/dist/template/docs/migrations/2026-09-02-ota-distribution-control.sql +377 -0
- package/dist/template/docs/migrations/schema.sql +561 -2
- package/dist/template/docs/operations-guide.md +52 -1
- package/dist/template/docs/ota-emergency-recovery.md +22 -0
- package/dist/template/docs/ota-update-policy.md +89 -0
- package/dist/template/docs/supabase-setup.md +2 -1
- package/dist/template/package-lock.json +2 -2
- package/dist/template/package.json +1 -1
- package/dist/template/scripts/configure-expo-app.mjs +6 -0
- package/dist/template/scripts/lib/embedded-update-registrar.test.ts +383 -3
- package/dist/template/scripts/lib/expo-app-configurator.mjs +165 -9
- package/dist/template/scripts/lib/expo-app-configurator.test.ts +658 -9
- package/dist/template/src/client/admin-api.ts +80 -1
- package/dist/template/src/client/admin-types.ts +52 -2
- package/dist/template/src/client/distribution-control.tsx +231 -0
- package/dist/template/src/client/guard-action-combobox.test.ts +26 -0
- package/dist/template/src/client/guard-action-combobox.tsx +267 -0
- package/dist/template/src/client/guard-action-options.test.ts +62 -0
- package/dist/template/src/client/guard-action-options.ts +70 -0
- package/dist/template/src/client/update-policy-editor.test.ts +36 -0
- package/dist/template/src/client/update-policy-editor.tsx +436 -0
- package/dist/template/src/server/controllers/assets.test.ts +87 -0
- package/dist/template/src/server/controllers/assets.ts +26 -0
- package/dist/template/src/server/controllers/manifest.test.ts +413 -2
- package/dist/template/src/server/controllers/manifest.ts +103 -38
- package/dist/template/src/server/lib/admin-distribution-guard.test.ts +61 -0
- package/dist/template/src/server/lib/admin-embedded-updates.test.ts +57 -0
- package/dist/template/src/server/lib/admin-embedded-updates.ts +42 -25
- package/dist/template/src/server/lib/admin-update-policy.test.ts +176 -0
- package/dist/template/src/server/lib/admin-updates.test.ts +133 -0
- package/dist/template/src/server/lib/admin-updates.ts +174 -9
- package/dist/template/src/server/lib/distribution-control-migration.test.ts +94 -0
- package/dist/template/src/server/lib/distribution-control.test.ts +160 -0
- package/dist/template/src/server/lib/distribution-control.ts +250 -0
- package/dist/template/src/server/lib/guard-actions-migration.test.ts +56 -0
- package/dist/template/src/server/lib/guard-actions.test.ts +142 -0
- package/dist/template/src/server/lib/guard-actions.ts +106 -0
- package/dist/template/src/server/lib/ota-policy-migrations.test.ts +64 -0
- package/dist/template/src/server/lib/simple-policy-migration.test.ts +97 -0
- package/dist/template/src/server/lib/supabase.js +95 -8
- package/dist/template/src/server/lib/supabase.test.ts +194 -0
- package/dist/template/src/server/lib/update-policy.test.ts +98 -0
- package/dist/template/src/server/lib/update-policy.ts +171 -0
- package/dist/template/src/server/manifest/manifest-repository.ts +10 -1
- package/dist/template/src/server/manifest/manifest-response.ts +0 -16
- package/dist/template/src/server/manifest/manifest-values.test.ts +54 -0
- package/dist/template/src/server/manifest/manifest-values.ts +145 -0
- package/dist/template/templates/expo-app/ci_scripts/ci_post_xcodebuild.sh +23 -1
- package/dist/template/templates/expo-app/plugins/with-ota-embedded-registration.js +13 -4
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/index.mjs +53 -7
- package/dist/template/templates/expo-app/scripts/ota-register-embedded/register-ios.sh +87 -0
- package/dist/template/tsconfig.json +4 -1
- package/dist/template-manifest.json +283 -88
- package/package.json +1 -1
- package/dist/template/templates/expo-app/ci_scripts/register-embedded-update.sh +0 -36
- /package/dist/template/templates/expo-app/scripts/ota-register-embedded/{android-register-embedded-update.sh → register-android.sh} +0 -0
|
@@ -233,6 +233,7 @@ ota_device_state
|
|
|
233
233
|
ota_device_transitions
|
|
234
234
|
ota_embedded_updates
|
|
235
235
|
ota_emergency_redirects
|
|
236
|
+
ota_guard_actions
|
|
236
237
|
ota_served_manifest_log
|
|
237
238
|
ota_update_channels
|
|
238
239
|
ota_updates
|
|
@@ -372,9 +373,14 @@ npm run ota:build:android:apk
|
|
|
372
373
|
```
|
|
373
374
|
|
|
374
375
|
Use `npm run ota:build:android:aab` for an App Bundle. After Gradle succeeds,
|
|
375
|
-
|
|
376
|
-
For iOS, the configurator adds an Xcode Build
|
|
377
|
-
|
|
376
|
+
`scripts/ota-register-embedded/register-android.sh` finds `app.manifest` and
|
|
377
|
+
registers the embedded update. For iOS, the configurator adds an Xcode Build
|
|
378
|
+
Phase that invokes `scripts/ota-register-embedded/register-ios.sh`, so a
|
|
379
|
+
Release/Archive build in Xcode performs registration automatically.
|
|
380
|
+
The registrar uses an app version from the embedded manifest when available;
|
|
381
|
+
otherwise it falls back to the normalized `expo.version` in the project's
|
|
382
|
+
static `app.json`. A missing or invalid fallback remains `null` and does not
|
|
383
|
+
fail an otherwise valid registration.
|
|
378
384
|
|
|
379
385
|
For remote CI or Xcode Cloud, do not provide PostgreSQL credentials. Create a
|
|
380
386
|
dedicated token:
|
|
@@ -391,10 +397,10 @@ OTA_SERVER_URL=https://updates.example.com
|
|
|
391
397
|
OTA_ACCESS_TOKEN=ota_...
|
|
392
398
|
```
|
|
393
399
|
|
|
394
|
-
The configurator also creates `ci_scripts/ci_post_xcodebuild.sh`,
|
|
395
|
-
Cloud
|
|
396
|
-
committed or included in the mobile binary.
|
|
397
|
-
`/updates/embedded`.
|
|
400
|
+
The configurator also creates `ci_scripts/ci_post_xcodebuild.sh`, a thin Xcode
|
|
401
|
+
Cloud lifecycle adapter that invokes the same `register-ios.sh`. The token is
|
|
402
|
+
shown only once and must never be committed or included in the mobile binary.
|
|
403
|
+
Verify registered binaries at `/updates/embedded`.
|
|
398
404
|
|
|
399
405
|
## Step 1. Install Expo Updates
|
|
400
406
|
|
|
@@ -282,7 +282,7 @@ OTA-сервер — приложение сервера всё равно ну
|
|
|
282
282
|
|
|
283
283
|
## Шаг 3. Проверьте таблицы
|
|
284
284
|
|
|
285
|
-
Откройте слева **Table Editor**. Должны появиться
|
|
285
|
+
Откройте слева **Table Editor**. Должны появиться 11 таблиц:
|
|
286
286
|
|
|
287
287
|
```text
|
|
288
288
|
ota_access_tokens
|
|
@@ -292,6 +292,7 @@ ota_device_state
|
|
|
292
292
|
ota_device_transitions
|
|
293
293
|
ota_embedded_updates
|
|
294
294
|
ota_emergency_redirects
|
|
295
|
+
ota_guard_actions
|
|
295
296
|
ota_served_manifest_log
|
|
296
297
|
ota_update_channels
|
|
297
298
|
ota_updates
|
|
@@ -474,9 +475,15 @@ npm run ota:build:android:apk
|
|
|
474
475
|
npm run ota:build:android:aab
|
|
475
476
|
```
|
|
476
477
|
|
|
477
|
-
После успешной Gradle-сборки
|
|
478
|
-
embedded
|
|
479
|
-
|
|
478
|
+
После успешной Gradle-сборки
|
|
479
|
+
`scripts/ota-register-embedded/register-android.sh` найдёт `app.manifest` и
|
|
480
|
+
зарегистрирует embedded update. Для iOS CLI добавляет Xcode Build Phase,
|
|
481
|
+
который вызывает `scripts/ota-register-embedded/register-ios.sh`, поэтому
|
|
482
|
+
достаточно собрать Release/Archive в Xcode.
|
|
483
|
+
Версия приложения сначала берётся из embedded manifest, а при её отсутствии —
|
|
484
|
+
из нормализованного `expo.version` в статическом `app.json` проекта. Если
|
|
485
|
+
fallback отсутствует или некорректен, `app_version` остаётся `null`, но
|
|
486
|
+
корректная в остальном регистрация не прерывается.
|
|
480
487
|
|
|
481
488
|
Для удалённого CI или Xcode Cloud не передавайте пароль PostgreSQL. Создайте
|
|
482
489
|
отдельный access token:
|
|
@@ -493,9 +500,10 @@ OTA_SERVER_URL=https://updates.example.com
|
|
|
493
500
|
OTA_ACCESS_TOKEN=ota_...
|
|
494
501
|
```
|
|
495
502
|
|
|
496
|
-
CLI также создаёт `ci_scripts/ci_post_xcodebuild.sh
|
|
497
|
-
|
|
498
|
-
|
|
503
|
+
CLI также создаёт `ci_scripts/ci_post_xcodebuild.sh` — тонкий lifecycle-адаптер
|
|
504
|
+
Xcode Cloud, который вызывает тот же `register-ios.sh`. Xcode Cloud
|
|
505
|
+
автоматически запустит его после сборки. Token показывается только один раз и
|
|
506
|
+
не должен попадать в Git или в mobile binary.
|
|
499
507
|
|
|
500
508
|
Зарегистрированные binary можно проверить в админ-панели на странице
|
|
501
509
|
`/updates/embedded`.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
alter table public.ota_embedded_updates
|
|
2
|
+
add column if not exists app_version text null;
|
|
3
|
+
|
|
4
|
+
create or replace function public.preserve_embedded_update_app_version()
|
|
5
|
+
returns trigger
|
|
6
|
+
language plpgsql
|
|
7
|
+
as $$
|
|
8
|
+
begin
|
|
9
|
+
if tg_op = 'UPDATE' and nullif(btrim(new.app_version), '') is null then
|
|
10
|
+
new.app_version := old.app_version;
|
|
11
|
+
else
|
|
12
|
+
new.app_version := nullif(btrim(new.app_version), '');
|
|
13
|
+
end if;
|
|
14
|
+
|
|
15
|
+
return new;
|
|
16
|
+
end;
|
|
17
|
+
$$;
|
|
18
|
+
|
|
19
|
+
drop trigger if exists trg_ota_embedded_updates_preserve_app_version
|
|
20
|
+
on public.ota_embedded_updates;
|
|
21
|
+
create trigger trg_ota_embedded_updates_preserve_app_version
|
|
22
|
+
before insert or update on public.ota_embedded_updates
|
|
23
|
+
for each row execute function public.preserve_embedded_update_app_version();
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
alter table public.ota_updates
|
|
2
|
+
add column if not exists delivery_mode text not null default 'manual',
|
|
3
|
+
add column if not exists guard_action text null,
|
|
4
|
+
add column if not exists guard_payload jsonb null,
|
|
5
|
+
add column if not exists policy_version integer not null default 1,
|
|
6
|
+
add column if not exists policy_published_at timestamptz null;
|
|
7
|
+
|
|
8
|
+
drop trigger if exists trg_ota_updates_lock_published_policy
|
|
9
|
+
on public.ota_updates;
|
|
10
|
+
|
|
11
|
+
alter table public.ota_updates
|
|
12
|
+
drop constraint if exists ota_updates_delivery_mode_chk,
|
|
13
|
+
add constraint ota_updates_delivery_mode_chk
|
|
14
|
+
check (delivery_mode in ('manual', 'background')),
|
|
15
|
+
drop constraint if exists ota_updates_guard_rules_array_chk,
|
|
16
|
+
drop constraint if exists ota_updates_guard_action_chk,
|
|
17
|
+
add constraint ota_updates_guard_action_chk check (
|
|
18
|
+
guard_action is null
|
|
19
|
+
or (
|
|
20
|
+
guard_action = btrim(guard_action)
|
|
21
|
+
and char_length(guard_action) between 1 and 100
|
|
22
|
+
and guard_action !~ '[[:cntrl:]]'
|
|
23
|
+
)
|
|
24
|
+
),
|
|
25
|
+
drop constraint if exists ota_updates_guard_payload_requires_action_chk,
|
|
26
|
+
add constraint ota_updates_guard_payload_requires_action_chk check (
|
|
27
|
+
guard_payload is null or guard_action is not null
|
|
28
|
+
),
|
|
29
|
+
drop constraint if exists ota_updates_policy_version_chk,
|
|
30
|
+
add constraint ota_updates_policy_version_chk
|
|
31
|
+
check (policy_version > 0),
|
|
32
|
+
drop column if exists guard_rules;
|
|
33
|
+
|
|
34
|
+
-- Active rows, rows disabled after their initial draft marker, rollback
|
|
35
|
+
-- targets, explicitly pinned rows, and demonstrably served rows have
|
|
36
|
+
-- participated in delivery. Uploads start inactive with disabled_at equal to
|
|
37
|
+
-- created_at; that initial marker is not a publication event.
|
|
38
|
+
update public.ota_updates u
|
|
39
|
+
set policy_published_at = coalesce(
|
|
40
|
+
u.updated_at,
|
|
41
|
+
u.disabled_at,
|
|
42
|
+
u.created_at,
|
|
43
|
+
now()
|
|
44
|
+
)
|
|
45
|
+
where u.policy_published_at is null
|
|
46
|
+
and (
|
|
47
|
+
u.is_active
|
|
48
|
+
or (
|
|
49
|
+
u.disabled_at is not null
|
|
50
|
+
and u.disabled_at is distinct from u.created_at
|
|
51
|
+
and u.updated_at is not null
|
|
52
|
+
)
|
|
53
|
+
or u.rolled_back_from_update_id is not null
|
|
54
|
+
or exists (
|
|
55
|
+
select 1
|
|
56
|
+
from public.ota_update_channels c
|
|
57
|
+
where c.active_update_id = u.update_id
|
|
58
|
+
)
|
|
59
|
+
or exists (
|
|
60
|
+
select 1
|
|
61
|
+
from public.ota_served_manifest_log sml
|
|
62
|
+
where sml.update_id = u.update_id
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
create or replace function public.ota_updates_lock_published_policy()
|
|
67
|
+
returns trigger
|
|
68
|
+
language plpgsql
|
|
69
|
+
as $$
|
|
70
|
+
begin
|
|
71
|
+
if tg_op = 'INSERT' then
|
|
72
|
+
if new.is_active and new.policy_published_at is null then
|
|
73
|
+
new.policy_published_at := coalesce(
|
|
74
|
+
new.updated_at,
|
|
75
|
+
new.created_at,
|
|
76
|
+
now()
|
|
77
|
+
);
|
|
78
|
+
end if;
|
|
79
|
+
return new;
|
|
80
|
+
end if;
|
|
81
|
+
|
|
82
|
+
if new.is_active and not old.is_active
|
|
83
|
+
and new.policy_published_at is null then
|
|
84
|
+
new.policy_published_at := coalesce(
|
|
85
|
+
new.updated_at,
|
|
86
|
+
new.created_at,
|
|
87
|
+
now()
|
|
88
|
+
);
|
|
89
|
+
end if;
|
|
90
|
+
|
|
91
|
+
if old.policy_published_at is not null and (
|
|
92
|
+
new.delivery_mode is distinct from old.delivery_mode
|
|
93
|
+
or new.guard_action is distinct from old.guard_action
|
|
94
|
+
or new.guard_payload is distinct from old.guard_payload
|
|
95
|
+
or new.policy_version is distinct from old.policy_version
|
|
96
|
+
or new.policy_published_at is distinct from old.policy_published_at
|
|
97
|
+
) then
|
|
98
|
+
raise exception 'OTA update policy is immutable after publication';
|
|
99
|
+
end if;
|
|
100
|
+
return new;
|
|
101
|
+
end;
|
|
102
|
+
$$;
|
|
103
|
+
|
|
104
|
+
drop trigger if exists trg_ota_updates_lock_published_policy
|
|
105
|
+
on public.ota_updates;
|
|
106
|
+
create trigger trg_ota_updates_lock_published_policy
|
|
107
|
+
before insert or update on public.ota_updates
|
|
108
|
+
for each row execute function public.ota_updates_lock_published_policy();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
create extension if not exists pgcrypto;
|
|
2
|
+
|
|
3
|
+
create table if not exists public.ota_guard_actions (
|
|
4
|
+
id uuid primary key default gen_random_uuid(),
|
|
5
|
+
action_key text not null,
|
|
6
|
+
created_at timestamptz not null default now(),
|
|
7
|
+
constraint ota_guard_actions_action_key_chk check (
|
|
8
|
+
action_key = btrim(action_key)
|
|
9
|
+
and char_length(action_key) between 1 and 100
|
|
10
|
+
and action_key !~ '[[:cntrl:]]'
|
|
11
|
+
)
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
create unique index if not exists idx_ota_guard_actions_action_key
|
|
15
|
+
on public.ota_guard_actions (action_key);
|
|
16
|
+
|
|
17
|
+
insert into public.ota_guard_actions (action_key)
|
|
18
|
+
values ('ota-force-store-update')
|
|
19
|
+
on conflict (action_key) do nothing;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
begin;
|
|
2
|
+
|
|
3
|
+
drop trigger if exists trg_ota_updates_lock_published_policy
|
|
4
|
+
on public.ota_updates;
|
|
5
|
+
|
|
6
|
+
alter table public.ota_updates
|
|
7
|
+
add column if not exists guard_action text null,
|
|
8
|
+
add column if not exists guard_payload jsonb null;
|
|
9
|
+
|
|
10
|
+
alter table public.ota_updates
|
|
11
|
+
drop constraint if exists ota_updates_guard_rules_array_chk,
|
|
12
|
+
drop constraint if exists ota_updates_guard_action_chk,
|
|
13
|
+
drop constraint if exists ota_updates_guard_payload_requires_action_chk,
|
|
14
|
+
drop column if exists guard_rules,
|
|
15
|
+
add constraint ota_updates_guard_action_chk check (
|
|
16
|
+
guard_action is null
|
|
17
|
+
or (
|
|
18
|
+
guard_action = btrim(guard_action)
|
|
19
|
+
and char_length(guard_action) between 1 and 100
|
|
20
|
+
and guard_action !~ '[[:cntrl:]]'
|
|
21
|
+
)
|
|
22
|
+
),
|
|
23
|
+
add constraint ota_updates_guard_payload_requires_action_chk check (
|
|
24
|
+
guard_payload is null or guard_action is not null
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
create or replace function public.ota_updates_lock_published_policy()
|
|
28
|
+
returns trigger
|
|
29
|
+
language plpgsql
|
|
30
|
+
as $$
|
|
31
|
+
begin
|
|
32
|
+
if tg_op = 'INSERT' then
|
|
33
|
+
if new.is_active and new.policy_published_at is null then
|
|
34
|
+
new.policy_published_at := coalesce(
|
|
35
|
+
new.updated_at,
|
|
36
|
+
new.created_at,
|
|
37
|
+
now()
|
|
38
|
+
);
|
|
39
|
+
end if;
|
|
40
|
+
return new;
|
|
41
|
+
end if;
|
|
42
|
+
|
|
43
|
+
if new.is_active and not old.is_active
|
|
44
|
+
and new.policy_published_at is null then
|
|
45
|
+
new.policy_published_at := coalesce(
|
|
46
|
+
new.updated_at,
|
|
47
|
+
new.created_at,
|
|
48
|
+
now()
|
|
49
|
+
);
|
|
50
|
+
end if;
|
|
51
|
+
|
|
52
|
+
if old.policy_published_at is not null and (
|
|
53
|
+
new.delivery_mode is distinct from old.delivery_mode
|
|
54
|
+
or new.guard_action is distinct from old.guard_action
|
|
55
|
+
or new.guard_payload is distinct from old.guard_payload
|
|
56
|
+
or new.policy_version is distinct from old.policy_version
|
|
57
|
+
or new.policy_published_at is distinct from old.policy_published_at
|
|
58
|
+
) then
|
|
59
|
+
raise exception 'OTA update policy is immutable after publication';
|
|
60
|
+
end if;
|
|
61
|
+
return new;
|
|
62
|
+
end;
|
|
63
|
+
$$;
|
|
64
|
+
|
|
65
|
+
create trigger trg_ota_updates_lock_published_policy
|
|
66
|
+
before insert or update on public.ota_updates
|
|
67
|
+
for each row execute function public.ota_updates_lock_published_policy();
|
|
68
|
+
|
|
69
|
+
commit;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
begin;
|
|
2
|
+
|
|
3
|
+
-- The original policy migration could mistake the upload-time disabled marker
|
|
4
|
+
-- for historical publication. Remove only markers on conservative,
|
|
5
|
+
-- never-published draft signatures. The trigger must be absent for this
|
|
6
|
+
-- one-time repair because clearing policy_published_at is otherwise correctly
|
|
7
|
+
-- rejected for published rows.
|
|
8
|
+
drop trigger if exists trg_ota_updates_lock_published_policy
|
|
9
|
+
on public.ota_updates;
|
|
10
|
+
|
|
11
|
+
update public.ota_updates u
|
|
12
|
+
set policy_published_at = null
|
|
13
|
+
where u.policy_published_at is not null
|
|
14
|
+
and u.policy_published_at = coalesce(
|
|
15
|
+
u.updated_at,
|
|
16
|
+
u.disabled_at,
|
|
17
|
+
u.created_at
|
|
18
|
+
)
|
|
19
|
+
and not u.is_active
|
|
20
|
+
and u.disabled_at is not null
|
|
21
|
+
and u.disabled_at = u.created_at
|
|
22
|
+
and u.delivery_mode = 'manual'
|
|
23
|
+
and u.guard_action is null
|
|
24
|
+
and u.guard_payload is null
|
|
25
|
+
and u.policy_version = 1
|
|
26
|
+
and u.rolled_back_from_update_id is null
|
|
27
|
+
and not exists (
|
|
28
|
+
select 1
|
|
29
|
+
from public.ota_served_manifest_log sml
|
|
30
|
+
where sml.update_id = u.update_id
|
|
31
|
+
)
|
|
32
|
+
-- latest_update_id tracks the newest upload and may reference this inactive
|
|
33
|
+
-- draft. It is intentionally not treated as publication evidence.
|
|
34
|
+
and not exists (
|
|
35
|
+
select 1
|
|
36
|
+
from public.ota_update_channels c
|
|
37
|
+
where c.active_update_id = u.update_id
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
create trigger trg_ota_updates_lock_published_policy
|
|
41
|
+
before insert or update on public.ota_updates
|
|
42
|
+
for each row execute function public.ota_updates_lock_published_policy();
|
|
43
|
+
|
|
44
|
+
commit;
|