@vrplatform/kysely 1.3.45-stage.344 → 1.3.45-stage.355

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.
@@ -0,0 +1,83 @@
1
+ import type { Kysely } from 'kysely';
2
+ import { sql } from 'kysely';
3
+
4
+ export async function up(db: Kysely<unknown>): Promise<void> {
5
+ await sql`
6
+ with desired_revisions as (
7
+ select
8
+ state.tenant_id,
9
+ state.reservation_id,
10
+ max(invalidation.revision) as desired_revision
11
+ from accounting.reservation_journal_state as state
12
+ inner join accounting.reservation_journal_invalidation as invalidation
13
+ on invalidation.tenant_id = state.tenant_id
14
+ and invalidation.reservation_id = state.reservation_id
15
+ and invalidation.revision > state.desired_revision
16
+ group by state.tenant_id, state.reservation_id
17
+ )
18
+ update accounting.reservation_journal_state as state
19
+ set
20
+ desired_revision = greatest(
21
+ state.desired_revision,
22
+ desired_revisions.desired_revision
23
+ ),
24
+ updated_at = now()
25
+ from desired_revisions
26
+ where state.tenant_id = desired_revisions.tenant_id
27
+ and state.reservation_id = desired_revisions.reservation_id
28
+ and state.desired_revision < desired_revisions.desired_revision
29
+ `.execute(db);
30
+
31
+ await sql`
32
+ with advancement as (
33
+ select
34
+ state.tenant_id,
35
+ state.reservation_id,
36
+ coalesce(
37
+ min(invalidation.revision) filter (
38
+ where invalidation.applied_at is null
39
+ ) - 1,
40
+ max(invalidation.revision),
41
+ state.applied_revision
42
+ ) as applied_revision,
43
+ min(invalidation.created_at) filter (
44
+ where invalidation.applied_at is null
45
+ ) as stale_since,
46
+ max(invalidation.applied_at) as calculated_at
47
+ from accounting.reservation_journal_state as state
48
+ left join accounting.reservation_journal_invalidation as invalidation
49
+ on invalidation.tenant_id = state.tenant_id
50
+ and invalidation.reservation_id = state.reservation_id
51
+ where state.desired_revision > state.applied_revision
52
+ group by
53
+ state.tenant_id,
54
+ state.reservation_id,
55
+ state.applied_revision
56
+ )
57
+ update accounting.reservation_journal_state as state
58
+ set
59
+ applied_revision = greatest(
60
+ state.applied_revision,
61
+ advancement.applied_revision
62
+ ),
63
+ stale_since = case
64
+ when greatest(
65
+ state.applied_revision,
66
+ advancement.applied_revision
67
+ ) >= state.desired_revision then null
68
+ else coalesce(state.stale_since, advancement.stale_since)
69
+ end,
70
+ calculated_at = case
71
+ when advancement.applied_revision > state.applied_revision
72
+ then greatest(state.calculated_at, advancement.calculated_at)
73
+ else state.calculated_at
74
+ end,
75
+ updated_at = now()
76
+ from advancement
77
+ where state.tenant_id = advancement.tenant_id
78
+ and state.reservation_id = advancement.reservation_id
79
+ and state.applied_revision < advancement.applied_revision
80
+ `.execute(db);
81
+ }
82
+
83
+ export async function down(_db: Kysely<unknown>): Promise<void> {}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.3.45-stage.344",
6
+ "version": "1.3.45-stage.355",
7
7
  "description": "",
8
8
  "main": "build/main/index.js",
9
9
  "module": "build/module/index.js",