@_nazmiforreal/flutter-ota 0.1.6 → 0.1.7
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/README.md +13 -13
- package/bin/{flutter-patcher-linux-x64 → flutter-ota-linux-x64} +0 -0
- package/bin/{flutter-patcher.js → flutter-ota.js} +4 -4
- package/dart-src/packages/cli-tools/bin/{flutter_patcher.dart → flutter_ota_kit.dart} +2 -2
- package/dart-src/packages/cli-tools/lib/{flutter_patcher_cli.dart → flutter_ota_kit_cli.dart} +5 -3
- package/dart-src/packages/cli-tools/lib/src/backend.dart +6 -25
- package/dart-src/packages/cli-tools/lib/src/cli_base.dart +10 -4
- package/dart-src/packages/cli-tools/lib/src/commands/build.dart +5 -3
- package/dart-src/packages/cli-tools/lib/src/commands/bundle.dart +279 -10
- package/dart-src/packages/cli-tools/lib/src/commands/channel.dart +7 -7
- package/dart-src/packages/cli-tools/lib/src/commands/config_command.dart +5 -5
- package/dart-src/packages/cli-tools/lib/src/commands/console.dart +4 -4
- package/dart-src/packages/cli-tools/lib/src/commands/deploy.dart +4 -4
- package/dart-src/packages/cli-tools/lib/src/commands/doctor.dart +3 -3
- package/dart-src/packages/cli-tools/lib/src/commands/fingerprint.dart +1 -1
- package/dart-src/packages/cli-tools/lib/src/commands/init.dart +294 -45
- package/dart-src/packages/cli-tools/lib/src/commands/keys.dart +1 -1
- package/dart-src/packages/cli-tools/lib/src/commands/migrate.dart +59 -24
- package/dart-src/packages/cli-tools/lib/src/commands/rollback.dart +5 -5
- package/dart-src/packages/cli-tools/lib/src/commands/storage.dart +117 -0
- package/dart-src/packages/cli-tools/lib/src/config.dart +29 -78
- package/dart-src/packages/cli-tools/lib/src/operations.dart +4 -4
- package/dart-src/packages/cli-tools/lib/src/pack.dart +12 -6
- package/dart-src/packages/cli-tools/lib/src/runner.dart +21 -3
- package/dart-src/packages/cli-tools/lib/src/ui/ui.dart +2 -2
- package/dart-src/packages/cli-tools/lib/src/verbose.dart +3 -0
- package/dart-src/packages/cli-tools/migrations/aws/README.md +7 -0
- package/dart-src/packages/cli-tools/migrations/postgres/bundles.sql +45 -0
- package/dart-src/packages/cli-tools/migrations/postgres/get_target_app_version_list.sql +21 -0
- package/dart-src/packages/cli-tools/migrations/postgres/get_update_info_by_app_version.sql +126 -0
- package/dart-src/packages/cli-tools/migrations/postgres/get_update_info_by_fingerprint_hash.sql +125 -0
- package/dart-src/packages/cli-tools/migrations/postgres/hash_user_id.sql +30 -0
- package/dart-src/packages/cli-tools/migrations/postgres/is_device_eligible.sql +237 -0
- package/dart-src/packages/cli-tools/migrations/supabase/20260520014100_hot-updater_rls.sql +11 -0
- package/dart-src/packages/cli-tools/pubspec.yaml +8 -10
- package/dart-src/packages/cli-tools/test/backends_test.dart +4 -4
- package/dart-src/packages/cli-tools/test/build_pack_test.dart +1 -1
- package/dart-src/packages/cli-tools/test/cli_test.dart +3 -3
- package/dart-src/packages/cli-tools/test/mocks/mock_aws_s3_client.dart +2 -2
- package/dart-src/packages/cli-tools/test/mocks/mock_d1_client.dart +2 -2
- package/dart-src/packages/cli-tools/test/mocks/mock_postgres_client.dart +7 -7
- package/dart-src/packages/core/lib/{flutter_patcher_core.dart → flutter_ota_kit_core.dart} +1 -1
- package/dart-src/packages/core/pubspec.yaml +2 -2
- package/dart-src/packages/core/test/rollout_test.dart +1 -1
- package/dart-src/packages/core/test/semver_test.dart +1 -1
- package/dart-src/packages/core/test/types_test.dart +2 -2
- package/dart-src/packages/core/test/uuid_test.dart +1 -1
- package/dart-src/packages/core/tool/dbg.dart +1 -1
- package/dart-src/plugins/aws/lib/{flutter_patcher_aws.dart → flutter_ota_kit_aws.dart} +0 -2
- package/dart-src/plugins/aws/lib/src/aws_cloudfront_client.dart +1 -1
- package/dart-src/plugins/aws/lib/src/aws_database.dart +1 -1
- package/dart-src/plugins/aws/lib/src/aws_s3_client.dart +1 -1
- package/dart-src/plugins/aws/lib/src/aws_storage.dart +1 -1
- package/dart-src/plugins/aws/lib/src/aws_storage_profile.dart +25 -3
- package/dart-src/plugins/aws/lib/src/with_cloudfront_signed_url.dart +1 -1
- package/dart-src/plugins/aws/pubspec.yaml +4 -4
- package/dart-src/plugins/aws/test/aws_database_test.dart +3 -3
- package/dart-src/plugins/aws/test/aws_storage_test.dart +2 -2
- package/dart-src/plugins/aws/test/mock_aws_s3_client.dart +2 -2
- package/dart-src/plugins/cloudflare/lib/src/cloudflare_worker_database.dart +1 -1
- package/dart-src/plugins/cloudflare/lib/src/d1_build_where.dart +1 -1
- package/dart-src/plugins/cloudflare/lib/src/d1_bundle_mapper.dart +1 -1
- package/dart-src/plugins/cloudflare/lib/src/d1_database.dart +1 -1
- package/dart-src/plugins/cloudflare/lib/src/d1_database_plugin.dart +2 -2
- package/dart-src/plugins/cloudflare/lib/src/r2_s3_client.dart +1 -1
- package/dart-src/plugins/cloudflare/lib/src/r2_storage.dart +1 -1
- package/dart-src/plugins/cloudflare/lib/src/r2_storage_profile.dart +1 -1
- package/dart-src/plugins/cloudflare/pubspec.yaml +4 -4
- package/dart-src/plugins/cloudflare/test/cloudflare_worker_database_test.dart +2 -2
- package/dart-src/plugins/cloudflare/test/d1_bundle_mapper_test.dart +2 -2
- package/dart-src/plugins/cloudflare/test/d1_database_test.dart +2 -2
- package/dart-src/plugins/cloudflare/test/mock_d1_client.dart +2 -2
- package/dart-src/plugins/cloudflare/test/mock_r2_client.dart +2 -2
- package/dart-src/plugins/cloudflare/test/r2_storage_test.dart +2 -2
- package/dart-src/plugins/plugin-core/lib/{flutter_patcher_plugin_core.dart → flutter_ota_kit_plugin_core.dart} +1 -1
- package/dart-src/plugins/plugin-core/lib/src/create_blob_database_plugin.dart +1 -1
- package/dart-src/plugins/plugin-core/lib/src/filter_compatible_app_versions.dart +1 -1
- package/dart-src/plugins/plugin-core/lib/src/get_update_info.dart +1 -1
- package/dart-src/plugins/plugin-core/lib/src/request_update_bundle_state.dart +1 -1
- package/dart-src/plugins/plugin-core/lib/src/resolve_update_info_from_bundles.dart +1 -1
- package/dart-src/plugins/plugin-core/lib/src/types.dart +2 -2
- package/dart-src/plugins/plugin-core/pubspec.yaml +3 -3
- package/dart-src/plugins/plugin-core/test/asset_storage_layout_test.dart +3 -3
- package/dart-src/plugins/plugin-core/test/bundle_unit_of_work_store_test.dart +2 -2
- package/dart-src/plugins/plugin-core/test/bundle_unit_of_work_test.dart +2 -2
- package/dart-src/plugins/plugin-core/test/create_blob_database_plugin_test.dart +2 -2
- package/dart-src/plugins/plugin-core/test/create_database_plugin_test.dart +5 -5
- package/dart-src/plugins/plugin-core/test/create_storage_plugin_test.dart +2 -2
- package/dart-src/plugins/plugin-core/test/generate_min_bundle_id_test.dart +2 -2
- package/dart-src/plugins/plugin-core/test/get_update_info_test.dart +2 -2
- package/dart-src/plugins/plugin-core/test/helpers_test.dart +2 -2
- package/dart-src/plugins/plugin-core/test/query_bundles_test.dart +2 -2
- package/dart-src/plugins/plugin-core/test/request_update_bundle_state_test.dart +3 -3
- package/dart-src/plugins/plugin-core/test/uuidv7_test.dart +1 -1
- package/dart-src/plugins/postgres/lib/{flutter_patcher_postgres.dart → flutter_ota_kit_postgres.dart} +1 -1
- package/dart-src/plugins/postgres/lib/src/postgres_bundle_mapper.dart +1 -1
- package/dart-src/plugins/postgres/lib/src/postgres_database.dart +2 -2
- package/dart-src/plugins/postgres/lib/src/postgres_get_update_info.dart +2 -2
- package/dart-src/plugins/postgres/lib/src/postgres_storage.dart +9 -9
- package/dart-src/plugins/postgres/lib/src/postgres_types.dart +1 -1
- package/dart-src/plugins/postgres/pubspec.yaml +4 -4
- package/dart-src/plugins/postgres/test/mock_postgres_client.dart +2 -2
- package/dart-src/plugins/postgres/test/postgres_bundle_mapper_test.dart +2 -2
- package/dart-src/plugins/postgres/test/postgres_database_test.dart +2 -2
- package/dart-src/plugins/supabase/lib/edge.dart +1 -1
- package/dart-src/plugins/supabase/lib/{flutter_patcher_supabase.dart → flutter_ota_kit_supabase.dart} +1 -1
- package/dart-src/plugins/supabase/lib/src/supabase_bundle_mapper.dart +1 -1
- package/dart-src/plugins/supabase/lib/src/supabase_client_http.dart +5 -1
- package/dart-src/plugins/supabase/lib/src/supabase_database.dart +2 -2
- package/dart-src/plugins/supabase/lib/src/supabase_edge_function_database.dart +1 -1
- package/dart-src/plugins/supabase/lib/src/supabase_edge_function_storage.dart +1 -1
- package/dart-src/plugins/supabase/lib/src/supabase_storage.dart +2 -5
- package/dart-src/plugins/supabase/pubspec.yaml +4 -4
- package/dart-src/plugins/supabase/test/mock_supabase_client.dart +5 -5
- package/dart-src/plugins/supabase/test/supabase_bundle_mapper_test.dart +3 -3
- package/dart-src/plugins/supabase/test/supabase_database_test.dart +3 -3
- package/dart-src/plugins/supabase/test/supabase_storage_test.dart +2 -2
- package/migrations/aws/README.md +7 -0
- package/migrations/cloudflare/0001_hot-updater_init.sql +16 -0
- package/migrations/cloudflare/0002_hot-updater_0.13.0.sql +8 -0
- package/migrations/cloudflare/0003_hot-updater_0.18.0.sql +38 -0
- package/migrations/cloudflare/0004_hot-updater_0.29.0.sql +11 -0
- package/migrations/cloudflare/0005_hot-updater_0.31.0.sql +24 -0
- package/migrations/cloudflare/bundles.sql +42 -0
- package/migrations/postgres/bundles.sql +45 -0
- package/migrations/postgres/get_target_app_version_list.sql +21 -0
- package/migrations/postgres/get_update_info_by_app_version.sql +126 -0
- package/migrations/postgres/get_update_info_by_fingerprint_hash.sql +125 -0
- package/migrations/postgres/hash_user_id.sql +30 -0
- package/migrations/postgres/is_device_eligible.sql +237 -0
- package/package.json +4 -4
- package/scripts/postinstall.js +15 -15
- package/scripts/vendor.sh +1 -1
- package/dart-src/packages/cli-tools/.dart_tool/package_config.json +0 -496
- package/dart-src/packages/cli-tools/.dart_tool/package_graph.json +0 -743
- package/dart-src/packages/cli-tools/pubspec.lock +0 -638
- package/dart-src/packages/cli-tools/test/standalone_backend_test.dart +0 -315
- package/dart-src/plugins/aws/lib/src/aws_lambda_edge_storage.dart +0 -72
- package/dart-src/plugins/aws/test/aws_lambda_edge_storage_test.dart +0 -190
- package/dart-src/plugins/standalone/.gitkeep +0 -0
- package/dart-src/plugins/standalone/lib/flutter_patcher_standalone.dart +0 -12
- package/dart-src/plugins/standalone/lib/src/standalone_config.dart +0 -107
- package/dart-src/plugins/standalone/lib/src/standalone_database.dart +0 -233
- package/dart-src/plugins/standalone/lib/src/standalone_storage.dart +0 -175
- package/dart-src/plugins/standalone/pubspec.yaml +0 -18
- package/dart-src/plugins/standalone/test/standalone_test.dart +0 -264
- /package/dart-src/plugins/cloudflare/lib/{flutter_patcher_cloudflare.dart → flutter_ota_kit_cloudflare.dart} +0 -0
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import 'dart:io';
|
|
2
2
|
|
|
3
|
+
import 'package:args/args.dart';
|
|
3
4
|
import 'package:args/command_runner.dart';
|
|
4
5
|
import 'ui/ui.dart';
|
|
6
|
+
import 'verbose.dart';
|
|
5
7
|
|
|
6
8
|
/// Custom [CommandRunner] that renders a clean, colorized top-level help.
|
|
7
9
|
class FlutterPatcherRunner extends CommandRunner<int> {
|
|
8
|
-
FlutterPatcherRunner(super.name, super.description)
|
|
10
|
+
FlutterPatcherRunner(super.name, super.description) {
|
|
11
|
+
argParser.addFlag(
|
|
12
|
+
'verbose',
|
|
13
|
+
abbr: 'v',
|
|
14
|
+
help: 'Show full error stack traces.',
|
|
15
|
+
negatable: false,
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@override
|
|
20
|
+
Future<int?> runCommand(ArgResults results) {
|
|
21
|
+
verboseMode = results['verbose'] as bool? ?? false;
|
|
22
|
+
return super.runCommand(results);
|
|
23
|
+
}
|
|
9
24
|
|
|
10
25
|
@override
|
|
11
26
|
String get usage {
|
|
@@ -29,6 +44,9 @@ class FlutterPatcherRunner extends CommandRunner<int> {
|
|
|
29
44
|
}
|
|
30
45
|
buf.writeln('');
|
|
31
46
|
buf.writeln(' ${dim('Run "$executableName help <command>" for more about a command.')}');
|
|
47
|
+
buf.writeln('');
|
|
48
|
+
buf.writeln(' ${bold('GLOBAL OPTIONS')}');
|
|
49
|
+
buf.writeln(' ${cyan('-v, --verbose')} ${dim('Show full error stack traces.')}');
|
|
32
50
|
return buf.toString();
|
|
33
51
|
}
|
|
34
52
|
|
|
@@ -48,8 +66,8 @@ String _fullName(Command<int> command) {
|
|
|
48
66
|
return parts.join(' ');
|
|
49
67
|
}
|
|
50
68
|
|
|
51
|
-
/// Base class for
|
|
52
|
-
/// per-command help (used by `
|
|
69
|
+
/// Base class for flutter_ota_kit commands; renders a clean, colorized
|
|
70
|
+
/// per-command help (used by `flutter_ota_kit <cmd> --help`).
|
|
53
71
|
abstract class FlutterPatcherCommand extends Command<int> {
|
|
54
72
|
@override
|
|
55
73
|
String get usage {
|
|
@@ -4,7 +4,7 @@ import 'dart:async';
|
|
|
4
4
|
import 'dart:io';
|
|
5
5
|
import 'dart:math' as math;
|
|
6
6
|
|
|
7
|
-
/// Terminal UI toolkit for the
|
|
7
|
+
/// Terminal UI toolkit for the flutter_ota_kit CLI: colored text, banners,
|
|
8
8
|
/// bordered boxes, step logs, dynamic spinners and progress bars.
|
|
9
9
|
///
|
|
10
10
|
/// Everything degrades gracefully to plain text when stdout is not a TTY or the
|
|
@@ -61,7 +61,7 @@ String kv(String k, String v) {
|
|
|
61
61
|
|
|
62
62
|
void banner(String name) {
|
|
63
63
|
_echo('');
|
|
64
|
-
_echo(' ${cyan('▶')} ${cyan(bold('
|
|
64
|
+
_echo(' ${cyan('▶')} ${cyan(bold('flutter_ota_kit'))} ${dim('·')} ${bold(name)}');
|
|
65
65
|
_echo(' ${dim('─' * math.min(_cols - 4, 60))}');
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# AWS migrations
|
|
2
|
+
|
|
3
|
+
The AWS backend stores bundle metadata as JSON in S3 (blob database), not in a
|
|
4
|
+
relational database. There are **no SQL migrations** to apply — the bucket and
|
|
5
|
+
object prefix are created on first `deploy`.
|
|
6
|
+
|
|
7
|
+
If you front downloads with CloudFront, provision the distribution separately.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
-- HotUpdater.bundles
|
|
2
|
+
|
|
3
|
+
CREATE TYPE platforms AS ENUM ('ios', 'android');
|
|
4
|
+
|
|
5
|
+
CREATE TABLE bundles (
|
|
6
|
+
id uuid PRIMARY KEY,
|
|
7
|
+
platform platforms NOT NULL,
|
|
8
|
+
should_force_update boolean NOT NULL,
|
|
9
|
+
enabled boolean NOT NULL,
|
|
10
|
+
file_hash text NOT NULL,
|
|
11
|
+
git_commit_hash text,
|
|
12
|
+
message text,
|
|
13
|
+
channel text NOT NULL DEFAULT 'production',
|
|
14
|
+
storage_uri text NOT NULL,
|
|
15
|
+
target_app_version text,
|
|
16
|
+
fingerprint_hash text,
|
|
17
|
+
CONSTRAINT check_version_or_fingerprint CHECK (
|
|
18
|
+
(target_app_version IS NOT NULL) OR (fingerprint_hash IS NOT NULL)
|
|
19
|
+
),
|
|
20
|
+
metadata jsonb DEFAULT '{}'::jsonb,
|
|
21
|
+
manifest_storage_uri text,
|
|
22
|
+
manifest_file_hash text,
|
|
23
|
+
asset_base_storage_uri text,
|
|
24
|
+
rollout_cohort_count INTEGER DEFAULT 1000
|
|
25
|
+
CHECK (rollout_cohort_count >= 0 AND rollout_cohort_count <= 1000),
|
|
26
|
+
target_cohorts TEXT[]
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
CREATE TABLE bundle_patches (
|
|
30
|
+
id text PRIMARY KEY,
|
|
31
|
+
bundle_id uuid NOT NULL REFERENCES bundles(id) ON DELETE CASCADE,
|
|
32
|
+
base_bundle_id uuid NOT NULL REFERENCES bundles(id) ON DELETE CASCADE,
|
|
33
|
+
base_file_hash text NOT NULL,
|
|
34
|
+
patch_file_hash text NOT NULL,
|
|
35
|
+
patch_storage_uri text NOT NULL,
|
|
36
|
+
order_index integer NOT NULL DEFAULT 0
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
CREATE INDEX bundles_target_app_version_idx ON bundles(target_app_version);
|
|
40
|
+
CREATE INDEX bundles_fingerprint_hash_idx ON bundles(fingerprint_hash);
|
|
41
|
+
CREATE INDEX bundles_channel_idx ON bundles(channel);
|
|
42
|
+
CREATE INDEX bundles_rollout_idx ON bundles(rollout_cohort_count);
|
|
43
|
+
CREATE INDEX bundles_target_cohorts_idx ON bundles USING GIN (target_cohorts);
|
|
44
|
+
CREATE INDEX bundle_patches_bundle_id_idx ON bundle_patches(bundle_id);
|
|
45
|
+
CREATE INDEX bundle_patches_base_bundle_id_idx ON bundle_patches(base_bundle_id);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-- HotUpdater.get_target_app_version_list
|
|
2
|
+
|
|
3
|
+
CREATE OR REPLACE FUNCTION get_target_app_version_list (
|
|
4
|
+
app_platform platforms,
|
|
5
|
+
min_bundle_id uuid
|
|
6
|
+
)
|
|
7
|
+
RETURNS TABLE (
|
|
8
|
+
target_app_version text
|
|
9
|
+
)
|
|
10
|
+
LANGUAGE plpgsql
|
|
11
|
+
AS
|
|
12
|
+
$$
|
|
13
|
+
BEGIN
|
|
14
|
+
RETURN QUERY
|
|
15
|
+
SELECT b.target_app_version
|
|
16
|
+
FROM bundles b
|
|
17
|
+
WHERE b.platform = app_platform
|
|
18
|
+
AND b.id >= min_bundle_id
|
|
19
|
+
GROUP BY b.target_app_version;
|
|
20
|
+
END;
|
|
21
|
+
$$;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
-- HotUpdater.get_update_info_by_app_version
|
|
2
|
+
|
|
3
|
+
DROP FUNCTION IF EXISTS get_update_info_by_app_version;
|
|
4
|
+
|
|
5
|
+
CREATE OR REPLACE FUNCTION get_update_info_by_app_version (
|
|
6
|
+
app_platform platforms,
|
|
7
|
+
app_version text,
|
|
8
|
+
bundle_id uuid,
|
|
9
|
+
min_bundle_id uuid,
|
|
10
|
+
target_channel text,
|
|
11
|
+
target_app_version_list text[],
|
|
12
|
+
cohort TEXT DEFAULT NULL
|
|
13
|
+
)
|
|
14
|
+
RETURNS TABLE (
|
|
15
|
+
id uuid,
|
|
16
|
+
should_force_update boolean,
|
|
17
|
+
message text,
|
|
18
|
+
status text,
|
|
19
|
+
storage_uri text,
|
|
20
|
+
file_hash text
|
|
21
|
+
)
|
|
22
|
+
LANGUAGE plpgsql
|
|
23
|
+
AS
|
|
24
|
+
$$
|
|
25
|
+
DECLARE
|
|
26
|
+
NIL_UUID CONSTANT uuid := '00000000-0000-0000-0000-000000000000';
|
|
27
|
+
BEGIN
|
|
28
|
+
RETURN QUERY
|
|
29
|
+
WITH candidate_bundles AS (
|
|
30
|
+
SELECT
|
|
31
|
+
b.id,
|
|
32
|
+
b.should_force_update,
|
|
33
|
+
b.message,
|
|
34
|
+
b.storage_uri,
|
|
35
|
+
b.file_hash,
|
|
36
|
+
b.rollout_cohort_count,
|
|
37
|
+
b.target_cohorts
|
|
38
|
+
FROM bundles b
|
|
39
|
+
WHERE b.enabled = TRUE
|
|
40
|
+
AND b.platform = app_platform
|
|
41
|
+
AND b.id >= min_bundle_id
|
|
42
|
+
AND b.target_app_version IN (SELECT unnest(target_app_version_list))
|
|
43
|
+
AND b.channel = target_channel
|
|
44
|
+
),
|
|
45
|
+
current_candidate AS (
|
|
46
|
+
SELECT
|
|
47
|
+
cb.id,
|
|
48
|
+
is_cohort_eligible(
|
|
49
|
+
cb.id,
|
|
50
|
+
cohort,
|
|
51
|
+
cb.rollout_cohort_count,
|
|
52
|
+
cb.target_cohorts
|
|
53
|
+
) AS is_eligible
|
|
54
|
+
FROM candidate_bundles cb
|
|
55
|
+
WHERE cb.id = bundle_id
|
|
56
|
+
LIMIT 1
|
|
57
|
+
),
|
|
58
|
+
eligible_update_candidate AS (
|
|
59
|
+
SELECT
|
|
60
|
+
cb.id,
|
|
61
|
+
cb.should_force_update,
|
|
62
|
+
cb.message,
|
|
63
|
+
'UPDATE' AS status,
|
|
64
|
+
cb.storage_uri,
|
|
65
|
+
cb.file_hash
|
|
66
|
+
FROM candidate_bundles cb
|
|
67
|
+
WHERE cb.id > bundle_id
|
|
68
|
+
AND is_cohort_eligible(
|
|
69
|
+
cb.id,
|
|
70
|
+
cohort,
|
|
71
|
+
cb.rollout_cohort_count,
|
|
72
|
+
cb.target_cohorts
|
|
73
|
+
)
|
|
74
|
+
ORDER BY cb.id DESC
|
|
75
|
+
LIMIT 1
|
|
76
|
+
),
|
|
77
|
+
rollback_candidate AS (
|
|
78
|
+
SELECT
|
|
79
|
+
cb.id,
|
|
80
|
+
TRUE AS should_force_update,
|
|
81
|
+
cb.message,
|
|
82
|
+
'ROLLBACK' AS status,
|
|
83
|
+
cb.storage_uri,
|
|
84
|
+
cb.file_hash
|
|
85
|
+
FROM candidate_bundles cb
|
|
86
|
+
WHERE cb.id < bundle_id
|
|
87
|
+
AND NOT EXISTS (
|
|
88
|
+
SELECT 1
|
|
89
|
+
FROM current_candidate
|
|
90
|
+
WHERE current_candidate.is_eligible = TRUE
|
|
91
|
+
)
|
|
92
|
+
AND NOT EXISTS (SELECT 1 FROM eligible_update_candidate)
|
|
93
|
+
ORDER BY cb.id DESC
|
|
94
|
+
LIMIT 1
|
|
95
|
+
),
|
|
96
|
+
final_result AS (
|
|
97
|
+
SELECT * FROM eligible_update_candidate
|
|
98
|
+
UNION ALL
|
|
99
|
+
SELECT * FROM rollback_candidate
|
|
100
|
+
WHERE NOT EXISTS (SELECT 1 FROM eligible_update_candidate)
|
|
101
|
+
)
|
|
102
|
+
SELECT *
|
|
103
|
+
FROM final_result
|
|
104
|
+
WHERE final_result.id != bundle_id
|
|
105
|
+
|
|
106
|
+
UNION ALL
|
|
107
|
+
|
|
108
|
+
SELECT
|
|
109
|
+
NIL_UUID AS id,
|
|
110
|
+
TRUE AS should_force_update,
|
|
111
|
+
NULL AS message,
|
|
112
|
+
'ROLLBACK' AS status,
|
|
113
|
+
NULL AS storage_uri,
|
|
114
|
+
NULL AS file_hash
|
|
115
|
+
WHERE (SELECT COUNT(*) FROM final_result) = 0
|
|
116
|
+
AND bundle_id != NIL_UUID
|
|
117
|
+
AND bundle_id > min_bundle_id
|
|
118
|
+
AND NOT EXISTS (
|
|
119
|
+
SELECT 1
|
|
120
|
+
FROM current_candidate
|
|
121
|
+
WHERE current_candidate.is_eligible = TRUE
|
|
122
|
+
)
|
|
123
|
+
AND NOT EXISTS (SELECT 1 FROM eligible_update_candidate)
|
|
124
|
+
AND NOT EXISTS (SELECT 1 FROM rollback_candidate);
|
|
125
|
+
END;
|
|
126
|
+
$$;
|
package/dart-src/packages/cli-tools/migrations/postgres/get_update_info_by_fingerprint_hash.sql
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
-- HotUpdater.get_update_info_by_fingerprint_hash
|
|
2
|
+
|
|
3
|
+
DROP FUNCTION IF EXISTS get_update_info_by_fingerprint_hash;
|
|
4
|
+
|
|
5
|
+
CREATE OR REPLACE FUNCTION get_update_info_by_fingerprint_hash (
|
|
6
|
+
app_platform platforms,
|
|
7
|
+
bundle_id uuid,
|
|
8
|
+
min_bundle_id uuid,
|
|
9
|
+
target_channel text,
|
|
10
|
+
target_fingerprint_hash text,
|
|
11
|
+
cohort TEXT DEFAULT NULL
|
|
12
|
+
)
|
|
13
|
+
RETURNS TABLE (
|
|
14
|
+
id uuid,
|
|
15
|
+
should_force_update boolean,
|
|
16
|
+
message text,
|
|
17
|
+
status text,
|
|
18
|
+
storage_uri text,
|
|
19
|
+
file_hash text
|
|
20
|
+
)
|
|
21
|
+
LANGUAGE plpgsql
|
|
22
|
+
AS
|
|
23
|
+
$$
|
|
24
|
+
DECLARE
|
|
25
|
+
NIL_UUID CONSTANT uuid := '00000000-0000-0000-0000-000000000000';
|
|
26
|
+
BEGIN
|
|
27
|
+
RETURN QUERY
|
|
28
|
+
WITH candidate_bundles AS (
|
|
29
|
+
SELECT
|
|
30
|
+
b.id,
|
|
31
|
+
b.should_force_update,
|
|
32
|
+
b.message,
|
|
33
|
+
b.storage_uri,
|
|
34
|
+
b.file_hash,
|
|
35
|
+
b.rollout_cohort_count,
|
|
36
|
+
b.target_cohorts
|
|
37
|
+
FROM bundles b
|
|
38
|
+
WHERE b.enabled = TRUE
|
|
39
|
+
AND b.platform = app_platform
|
|
40
|
+
AND b.id >= min_bundle_id
|
|
41
|
+
AND b.channel = target_channel
|
|
42
|
+
AND b.fingerprint_hash = target_fingerprint_hash
|
|
43
|
+
),
|
|
44
|
+
current_candidate AS (
|
|
45
|
+
SELECT
|
|
46
|
+
cb.id,
|
|
47
|
+
is_cohort_eligible(
|
|
48
|
+
cb.id,
|
|
49
|
+
cohort,
|
|
50
|
+
cb.rollout_cohort_count,
|
|
51
|
+
cb.target_cohorts
|
|
52
|
+
) AS is_eligible
|
|
53
|
+
FROM candidate_bundles cb
|
|
54
|
+
WHERE cb.id = bundle_id
|
|
55
|
+
LIMIT 1
|
|
56
|
+
),
|
|
57
|
+
eligible_update_candidate AS (
|
|
58
|
+
SELECT
|
|
59
|
+
cb.id,
|
|
60
|
+
cb.should_force_update,
|
|
61
|
+
cb.message,
|
|
62
|
+
'UPDATE' AS status,
|
|
63
|
+
cb.storage_uri,
|
|
64
|
+
cb.file_hash
|
|
65
|
+
FROM candidate_bundles cb
|
|
66
|
+
WHERE cb.id > bundle_id
|
|
67
|
+
AND is_cohort_eligible(
|
|
68
|
+
cb.id,
|
|
69
|
+
cohort,
|
|
70
|
+
cb.rollout_cohort_count,
|
|
71
|
+
cb.target_cohorts
|
|
72
|
+
)
|
|
73
|
+
ORDER BY cb.id DESC
|
|
74
|
+
LIMIT 1
|
|
75
|
+
),
|
|
76
|
+
rollback_candidate AS (
|
|
77
|
+
SELECT
|
|
78
|
+
cb.id,
|
|
79
|
+
TRUE AS should_force_update,
|
|
80
|
+
cb.message,
|
|
81
|
+
'ROLLBACK' AS status,
|
|
82
|
+
cb.storage_uri,
|
|
83
|
+
cb.file_hash
|
|
84
|
+
FROM candidate_bundles cb
|
|
85
|
+
WHERE cb.id < bundle_id
|
|
86
|
+
AND NOT EXISTS (
|
|
87
|
+
SELECT 1
|
|
88
|
+
FROM current_candidate
|
|
89
|
+
WHERE current_candidate.is_eligible = TRUE
|
|
90
|
+
)
|
|
91
|
+
AND NOT EXISTS (SELECT 1 FROM eligible_update_candidate)
|
|
92
|
+
ORDER BY cb.id DESC
|
|
93
|
+
LIMIT 1
|
|
94
|
+
),
|
|
95
|
+
final_result AS (
|
|
96
|
+
SELECT * FROM eligible_update_candidate
|
|
97
|
+
UNION ALL
|
|
98
|
+
SELECT * FROM rollback_candidate
|
|
99
|
+
WHERE NOT EXISTS (SELECT 1 FROM eligible_update_candidate)
|
|
100
|
+
)
|
|
101
|
+
SELECT *
|
|
102
|
+
FROM final_result
|
|
103
|
+
WHERE final_result.id != bundle_id
|
|
104
|
+
|
|
105
|
+
UNION ALL
|
|
106
|
+
|
|
107
|
+
SELECT
|
|
108
|
+
NIL_UUID AS id,
|
|
109
|
+
TRUE AS should_force_update,
|
|
110
|
+
NULL AS message,
|
|
111
|
+
'ROLLBACK' AS status,
|
|
112
|
+
NULL AS storage_uri,
|
|
113
|
+
NULL AS file_hash
|
|
114
|
+
WHERE (SELECT COUNT(*) FROM final_result) = 0
|
|
115
|
+
AND bundle_id != NIL_UUID
|
|
116
|
+
AND bundle_id > min_bundle_id
|
|
117
|
+
AND NOT EXISTS (
|
|
118
|
+
SELECT 1
|
|
119
|
+
FROM current_candidate
|
|
120
|
+
WHERE current_candidate.is_eligible = TRUE
|
|
121
|
+
)
|
|
122
|
+
AND NOT EXISTS (SELECT 1 FROM eligible_update_candidate)
|
|
123
|
+
AND NOT EXISTS (SELECT 1 FROM rollback_candidate);
|
|
124
|
+
END;
|
|
125
|
+
$$;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- Deterministic hash function matching JavaScript implementation
|
|
2
|
+
-- Returns hash value in range [0, 99]
|
|
3
|
+
CREATE OR REPLACE FUNCTION hash_user_id(user_id TEXT)
|
|
4
|
+
RETURNS INTEGER
|
|
5
|
+
LANGUAGE plpgsql
|
|
6
|
+
IMMUTABLE
|
|
7
|
+
AS $$
|
|
8
|
+
DECLARE
|
|
9
|
+
hash BIGINT := 0;
|
|
10
|
+
char_code INTEGER;
|
|
11
|
+
i INTEGER;
|
|
12
|
+
normalized BIGINT;
|
|
13
|
+
BEGIN
|
|
14
|
+
-- Replicate JavaScript hash algorithm
|
|
15
|
+
FOR i IN 1..length(user_id) LOOP
|
|
16
|
+
char_code := ascii(substring(user_id from i for 1));
|
|
17
|
+
hash := (hash * 31) + char_code;
|
|
18
|
+
|
|
19
|
+
-- Simulate JavaScript's |= 0 by wrapping into a signed 32-bit range.
|
|
20
|
+
normalized := mod(hash + 2147483648, 4294967296);
|
|
21
|
+
IF normalized < 0 THEN
|
|
22
|
+
normalized := normalized + 4294967296;
|
|
23
|
+
END IF;
|
|
24
|
+
hash := normalized - 2147483648;
|
|
25
|
+
END LOOP;
|
|
26
|
+
|
|
27
|
+
-- Return absolute value modulo 100
|
|
28
|
+
RETURN abs(hash % 100);
|
|
29
|
+
END;
|
|
30
|
+
$$;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
-- HotUpdater.is_cohort_eligible
|
|
2
|
+
-- Cohort eligibility helpers matching @hot-updater/core rollout.ts
|
|
3
|
+
|
|
4
|
+
CREATE OR REPLACE FUNCTION positive_mod(
|
|
5
|
+
value INTEGER,
|
|
6
|
+
modulus INTEGER
|
|
7
|
+
)
|
|
8
|
+
RETURNS INTEGER
|
|
9
|
+
LANGUAGE plpgsql
|
|
10
|
+
IMMUTABLE
|
|
11
|
+
AS $$
|
|
12
|
+
BEGIN
|
|
13
|
+
RETURN ((value % modulus) + modulus) % modulus;
|
|
14
|
+
END;
|
|
15
|
+
$$;
|
|
16
|
+
|
|
17
|
+
CREATE OR REPLACE FUNCTION hash_rollout_value(input TEXT)
|
|
18
|
+
RETURNS INTEGER
|
|
19
|
+
LANGUAGE plpgsql
|
|
20
|
+
IMMUTABLE
|
|
21
|
+
AS $$
|
|
22
|
+
DECLARE
|
|
23
|
+
hash_value NUMERIC := 0;
|
|
24
|
+
char_code INTEGER;
|
|
25
|
+
i INTEGER;
|
|
26
|
+
BEGIN
|
|
27
|
+
FOR i IN 1..length(input) LOOP
|
|
28
|
+
char_code := ascii(substring(input from i for 1));
|
|
29
|
+
hash_value := mod((hash_value * 31) + char_code, 4294967296);
|
|
30
|
+
END LOOP;
|
|
31
|
+
|
|
32
|
+
IF hash_value >= 2147483648 THEN
|
|
33
|
+
hash_value := hash_value - 4294967296;
|
|
34
|
+
END IF;
|
|
35
|
+
|
|
36
|
+
RETURN hash_value::INTEGER;
|
|
37
|
+
END;
|
|
38
|
+
$$;
|
|
39
|
+
|
|
40
|
+
CREATE OR REPLACE FUNCTION normalize_cohort_value(cohort TEXT)
|
|
41
|
+
RETURNS TEXT
|
|
42
|
+
LANGUAGE plpgsql
|
|
43
|
+
IMMUTABLE
|
|
44
|
+
AS $$
|
|
45
|
+
DECLARE
|
|
46
|
+
normalized TEXT;
|
|
47
|
+
cohort_value INTEGER;
|
|
48
|
+
BEGIN
|
|
49
|
+
IF cohort IS NULL THEN
|
|
50
|
+
RETURN NULL;
|
|
51
|
+
END IF;
|
|
52
|
+
|
|
53
|
+
normalized := lower(btrim(cohort));
|
|
54
|
+
|
|
55
|
+
IF normalized ~ '^[0-9]+$' THEN
|
|
56
|
+
cohort_value := normalized::INTEGER;
|
|
57
|
+
IF cohort_value BETWEEN 1 AND 1000 THEN
|
|
58
|
+
RETURN cohort_value::TEXT;
|
|
59
|
+
END IF;
|
|
60
|
+
END IF;
|
|
61
|
+
|
|
62
|
+
RETURN normalized;
|
|
63
|
+
END;
|
|
64
|
+
$$;
|
|
65
|
+
|
|
66
|
+
CREATE OR REPLACE FUNCTION gcd_int(a INTEGER, b INTEGER)
|
|
67
|
+
RETURNS INTEGER
|
|
68
|
+
LANGUAGE plpgsql
|
|
69
|
+
IMMUTABLE
|
|
70
|
+
AS $$
|
|
71
|
+
DECLARE
|
|
72
|
+
x INTEGER := abs(a);
|
|
73
|
+
y INTEGER := abs(b);
|
|
74
|
+
next_value INTEGER;
|
|
75
|
+
BEGIN
|
|
76
|
+
WHILE y <> 0 LOOP
|
|
77
|
+
next_value := x % y;
|
|
78
|
+
x := y;
|
|
79
|
+
y := next_value;
|
|
80
|
+
END LOOP;
|
|
81
|
+
|
|
82
|
+
RETURN x;
|
|
83
|
+
END;
|
|
84
|
+
$$;
|
|
85
|
+
|
|
86
|
+
CREATE OR REPLACE FUNCTION get_rollout_multiplier(bundle_id UUID)
|
|
87
|
+
RETURNS INTEGER
|
|
88
|
+
LANGUAGE plpgsql
|
|
89
|
+
IMMUTABLE
|
|
90
|
+
AS $$
|
|
91
|
+
DECLARE
|
|
92
|
+
candidate INTEGER := positive_mod(
|
|
93
|
+
hash_rollout_value(bundle_id::TEXT || ':multiplier'),
|
|
94
|
+
997
|
|
95
|
+
);
|
|
96
|
+
BEGIN
|
|
97
|
+
IF candidate = 0 THEN
|
|
98
|
+
candidate := 1;
|
|
99
|
+
END IF;
|
|
100
|
+
|
|
101
|
+
WHILE gcd_int(candidate, 1000) <> 1 LOOP
|
|
102
|
+
candidate := positive_mod(candidate + 1, 1000);
|
|
103
|
+
IF candidate = 0 THEN
|
|
104
|
+
candidate := 1;
|
|
105
|
+
END IF;
|
|
106
|
+
END LOOP;
|
|
107
|
+
|
|
108
|
+
RETURN candidate;
|
|
109
|
+
END;
|
|
110
|
+
$$;
|
|
111
|
+
|
|
112
|
+
CREATE OR REPLACE FUNCTION get_rollout_offset(bundle_id UUID)
|
|
113
|
+
RETURNS INTEGER
|
|
114
|
+
LANGUAGE plpgsql
|
|
115
|
+
IMMUTABLE
|
|
116
|
+
AS $$
|
|
117
|
+
BEGIN
|
|
118
|
+
RETURN positive_mod(hash_rollout_value(bundle_id::TEXT || ':offset'), 1000);
|
|
119
|
+
END;
|
|
120
|
+
$$;
|
|
121
|
+
|
|
122
|
+
CREATE OR REPLACE FUNCTION get_modular_inverse(value INTEGER, modulus INTEGER)
|
|
123
|
+
RETURNS INTEGER
|
|
124
|
+
LANGUAGE plpgsql
|
|
125
|
+
IMMUTABLE
|
|
126
|
+
AS $$
|
|
127
|
+
DECLARE
|
|
128
|
+
candidate INTEGER;
|
|
129
|
+
BEGIN
|
|
130
|
+
FOR candidate IN 1..(modulus - 1) LOOP
|
|
131
|
+
IF positive_mod(value * candidate, modulus) = 1 THEN
|
|
132
|
+
RETURN candidate;
|
|
133
|
+
END IF;
|
|
134
|
+
END LOOP;
|
|
135
|
+
|
|
136
|
+
RAISE EXCEPTION 'No modular inverse for % mod %', value, modulus;
|
|
137
|
+
END;
|
|
138
|
+
$$;
|
|
139
|
+
|
|
140
|
+
CREATE OR REPLACE FUNCTION is_numeric_cohort(cohort TEXT)
|
|
141
|
+
RETURNS BOOLEAN
|
|
142
|
+
LANGUAGE plpgsql
|
|
143
|
+
IMMUTABLE
|
|
144
|
+
AS $$
|
|
145
|
+
DECLARE
|
|
146
|
+
normalized_cohort TEXT := normalize_cohort_value(cohort);
|
|
147
|
+
cohort_value INTEGER;
|
|
148
|
+
BEGIN
|
|
149
|
+
IF normalized_cohort IS NULL OR normalized_cohort !~ '^[0-9]+$' THEN
|
|
150
|
+
RETURN FALSE;
|
|
151
|
+
END IF;
|
|
152
|
+
|
|
153
|
+
cohort_value := normalized_cohort::INTEGER;
|
|
154
|
+
RETURN cohort_value BETWEEN 1 AND 1000;
|
|
155
|
+
END;
|
|
156
|
+
$$;
|
|
157
|
+
|
|
158
|
+
CREATE OR REPLACE FUNCTION get_numeric_cohort_rollout_position(
|
|
159
|
+
bundle_id UUID,
|
|
160
|
+
cohort TEXT
|
|
161
|
+
)
|
|
162
|
+
RETURNS INTEGER
|
|
163
|
+
LANGUAGE plpgsql
|
|
164
|
+
IMMUTABLE
|
|
165
|
+
AS $$
|
|
166
|
+
DECLARE
|
|
167
|
+
normalized_cohort TEXT := normalize_cohort_value(cohort);
|
|
168
|
+
cohort_value INTEGER;
|
|
169
|
+
multiplier INTEGER;
|
|
170
|
+
offset_value INTEGER;
|
|
171
|
+
inverse_multiplier INTEGER;
|
|
172
|
+
BEGIN
|
|
173
|
+
IF NOT is_numeric_cohort(normalized_cohort) THEN
|
|
174
|
+
RAISE EXCEPTION 'Invalid numeric cohort: %', cohort;
|
|
175
|
+
END IF;
|
|
176
|
+
|
|
177
|
+
cohort_value := normalized_cohort::INTEGER - 1;
|
|
178
|
+
multiplier := get_rollout_multiplier(bundle_id);
|
|
179
|
+
offset_value := get_rollout_offset(bundle_id);
|
|
180
|
+
inverse_multiplier := get_modular_inverse(multiplier, 1000);
|
|
181
|
+
|
|
182
|
+
RETURN positive_mod(
|
|
183
|
+
inverse_multiplier * (cohort_value - offset_value),
|
|
184
|
+
1000
|
|
185
|
+
);
|
|
186
|
+
END;
|
|
187
|
+
$$;
|
|
188
|
+
|
|
189
|
+
CREATE OR REPLACE FUNCTION is_cohort_eligible(
|
|
190
|
+
bundle_id UUID,
|
|
191
|
+
cohort TEXT,
|
|
192
|
+
rollout_cohort_count INTEGER,
|
|
193
|
+
target_cohorts TEXT[]
|
|
194
|
+
)
|
|
195
|
+
RETURNS BOOLEAN
|
|
196
|
+
LANGUAGE plpgsql
|
|
197
|
+
IMMUTABLE
|
|
198
|
+
AS $$
|
|
199
|
+
DECLARE
|
|
200
|
+
normalized_cohort TEXT := normalize_cohort_value(cohort);
|
|
201
|
+
normalized_rollout_count INTEGER := COALESCE(rollout_cohort_count, 1000);
|
|
202
|
+
normalized_target_cohorts TEXT[];
|
|
203
|
+
BEGIN
|
|
204
|
+
IF target_cohorts IS NOT NULL THEN
|
|
205
|
+
normalized_target_cohorts := ARRAY(
|
|
206
|
+
SELECT normalize_cohort_value(value)
|
|
207
|
+
FROM unnest(target_cohorts) AS value
|
|
208
|
+
);
|
|
209
|
+
END IF;
|
|
210
|
+
|
|
211
|
+
IF normalized_target_cohorts IS NOT NULL
|
|
212
|
+
AND array_length(normalized_target_cohorts, 1) > 0
|
|
213
|
+
AND normalized_cohort IS NOT NULL
|
|
214
|
+
AND normalized_cohort = ANY(normalized_target_cohorts) THEN
|
|
215
|
+
RETURN TRUE;
|
|
216
|
+
END IF;
|
|
217
|
+
|
|
218
|
+
IF normalized_rollout_count <= 0 THEN
|
|
219
|
+
RETURN FALSE;
|
|
220
|
+
END IF;
|
|
221
|
+
|
|
222
|
+
IF normalized_cohort IS NULL THEN
|
|
223
|
+
RETURN normalized_rollout_count >= 1000;
|
|
224
|
+
END IF;
|
|
225
|
+
|
|
226
|
+
IF NOT is_numeric_cohort(normalized_cohort) THEN
|
|
227
|
+
RETURN FALSE;
|
|
228
|
+
END IF;
|
|
229
|
+
|
|
230
|
+
IF normalized_rollout_count >= 1000 THEN
|
|
231
|
+
RETURN TRUE;
|
|
232
|
+
END IF;
|
|
233
|
+
|
|
234
|
+
RETURN get_numeric_cohort_rollout_position(bundle_id, normalized_cohort)
|
|
235
|
+
< normalized_rollout_count;
|
|
236
|
+
END;
|
|
237
|
+
$$;
|
|
@@ -46,3 +46,14 @@ ALTER FUNCTION public.get_update_info_by_app_version(
|
|
|
46
46
|
text
|
|
47
47
|
)
|
|
48
48
|
SET search_path = public, pg_catalog;
|
|
49
|
+
|
|
50
|
+
-- OTA update checks are unauthenticated by design (the device only carries the
|
|
51
|
+
-- anon key), so bundle metadata must be publicly readable. hot-updater's hosted
|
|
52
|
+
-- Supabase flow relies on these policies existing.
|
|
53
|
+
CREATE POLICY "allow public read bundles" ON public.bundles FOR SELECT USING (true);
|
|
54
|
+
CREATE POLICY "allow public read bundle_patches" ON public.bundle_patches FOR SELECT USING (true);
|
|
55
|
+
|
|
56
|
+
-- Allow anon/authenticated to resolve signed download URLs for the bundles bucket.
|
|
57
|
+
CREATE POLICY "public bundles read" ON storage.objects
|
|
58
|
+
FOR SELECT TO anon, authenticated
|
|
59
|
+
USING (bucket_id = 'bundles');
|