@nymbalhq/platform 0.0.0-stage → 0.2.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.
- package/dist/chunk-74KODSYJ.js +2564 -0
- package/dist/chunk-74KODSYJ.js.map +1 -0
- package/dist/chunk-PW6ILJF7.js +740 -0
- package/dist/chunk-PW6ILJF7.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/db/schema/index.d.ts +10125 -0
- package/dist/db/schema/index.js +10 -0
- package/dist/db/schema/index.js.map +1 -0
- package/dist/index.d.ts +1372 -0
- package/dist/index.js +6652 -0
- package/dist/index.js.map +1 -0
- package/dist/register-IVFYBJSX.js +8 -0
- package/dist/register-IVFYBJSX.js.map +1 -0
- package/drizzle.config.postgres.ts +10 -0
- package/drizzle.config.sqlite.ts +10 -0
- package/migrations/postgres/0000_tearful_longshot.sql +166 -0
- package/migrations/postgres/0001_neat_zeigeist.sql +1 -0
- package/migrations/postgres/0002_sloppy_mad_thinker.sql +20 -0
- package/migrations/postgres/0003_violet_violations.sql +15 -0
- package/migrations/postgres/0004_white_reavers.sql +15 -0
- package/migrations/postgres/0005_natural_nico_minoru.sql +12 -0
- package/migrations/postgres/0006_minor_dragon_man.sql +28 -0
- package/migrations/postgres/meta/0000_snapshot.json +1172 -0
- package/migrations/postgres/meta/0001_snapshot.json +1187 -0
- package/migrations/postgres/meta/0002_snapshot.json +1325 -0
- package/migrations/postgres/meta/0003_snapshot.json +1432 -0
- package/migrations/postgres/meta/0004_snapshot.json +1439 -0
- package/migrations/postgres/meta/0005_snapshot.json +1461 -0
- package/migrations/postgres/meta/0006_snapshot.json +1598 -0
- package/migrations/postgres/meta/_journal.json +55 -0
- package/migrations/sqlite/0000_glorious_vision.sql +166 -0
- package/migrations/sqlite/0001_tricky_glorian.sql +1 -0
- package/migrations/sqlite/0002_puzzling_epoch.sql +19 -0
- package/migrations/sqlite/0003_fantastic_captain_stacy.sql +15 -0
- package/migrations/sqlite/0004_remarkable_shriek.sql +12 -0
- package/migrations/sqlite/0005_conscious_speedball.sql +13 -0
- package/migrations/sqlite/0006_flat_psylocke.sql +28 -0
- package/migrations/sqlite/meta/0000_snapshot.json +1093 -0
- package/migrations/sqlite/meta/0001_snapshot.json +1100 -0
- package/migrations/sqlite/meta/0002_snapshot.json +1222 -0
- package/migrations/sqlite/meta/0003_snapshot.json +1320 -0
- package/migrations/sqlite/meta/0004_snapshot.json +1328 -0
- package/migrations/sqlite/meta/0005_snapshot.json +1343 -0
- package/migrations/sqlite/meta/0006_snapshot.json +1470 -0
- package/migrations/sqlite/meta/_journal.json +55 -0
- package/package.json +69 -3
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineConfig } from 'drizzle-kit'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
dialect: 'postgresql',
|
|
5
|
+
schema: './src/db/schema/postgres.ts',
|
|
6
|
+
out: './migrations/postgres',
|
|
7
|
+
dbCredentials: {
|
|
8
|
+
url: process.env.DATABASE_URL ?? 'postgres://localhost:5432/nymbal',
|
|
9
|
+
},
|
|
10
|
+
})
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS "categories" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"parent_id" text,
|
|
4
|
+
"slug" text NOT NULL,
|
|
5
|
+
"name" text NOT NULL,
|
|
6
|
+
"description" text DEFAULT '' NOT NULL,
|
|
7
|
+
"position" integer DEFAULT 0 NOT NULL,
|
|
8
|
+
"created_at" timestamp with time zone NOT NULL
|
|
9
|
+
);
|
|
10
|
+
--> statement-breakpoint
|
|
11
|
+
CREATE TABLE IF NOT EXISTS "customers" (
|
|
12
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
13
|
+
"email" text NOT NULL,
|
|
14
|
+
"password_hash" text NOT NULL,
|
|
15
|
+
"first_name" text DEFAULT '' NOT NULL,
|
|
16
|
+
"last_name" text DEFAULT '' NOT NULL,
|
|
17
|
+
"phone" text DEFAULT '' NOT NULL,
|
|
18
|
+
"addresses" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
|
19
|
+
"order_count" integer DEFAULT 0 NOT NULL,
|
|
20
|
+
"total_spent_minor" integer DEFAULT 0 NOT NULL,
|
|
21
|
+
"metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
22
|
+
"requires_password_reset" boolean DEFAULT false NOT NULL,
|
|
23
|
+
"created_at" timestamp with time zone NOT NULL,
|
|
24
|
+
"updated_at" timestamp with time zone NOT NULL
|
|
25
|
+
);
|
|
26
|
+
--> statement-breakpoint
|
|
27
|
+
CREATE TABLE IF NOT EXISTS "inventory_reservations" (
|
|
28
|
+
"reservation_id" text PRIMARY KEY NOT NULL,
|
|
29
|
+
"variant_id" text NOT NULL,
|
|
30
|
+
"qty" integer NOT NULL,
|
|
31
|
+
"order_ref" text,
|
|
32
|
+
"expires_at" timestamp with time zone NOT NULL,
|
|
33
|
+
"created_at" timestamp with time zone NOT NULL
|
|
34
|
+
);
|
|
35
|
+
--> statement-breakpoint
|
|
36
|
+
CREATE TABLE IF NOT EXISTS "order_history" (
|
|
37
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
38
|
+
"order_id" text NOT NULL,
|
|
39
|
+
"from_status" text,
|
|
40
|
+
"to_status" text NOT NULL,
|
|
41
|
+
"actor" text NOT NULL,
|
|
42
|
+
"note" text DEFAULT '' NOT NULL,
|
|
43
|
+
"timestamp" timestamp with time zone NOT NULL
|
|
44
|
+
);
|
|
45
|
+
--> statement-breakpoint
|
|
46
|
+
CREATE TABLE IF NOT EXISTS "order_sequences" (
|
|
47
|
+
"id" integer PRIMARY KEY NOT NULL,
|
|
48
|
+
"next_value" integer NOT NULL
|
|
49
|
+
);
|
|
50
|
+
--> statement-breakpoint
|
|
51
|
+
CREATE TABLE IF NOT EXISTS "orders" (
|
|
52
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
53
|
+
"order_number" text NOT NULL,
|
|
54
|
+
"sequence" integer NOT NULL,
|
|
55
|
+
"customer_id" text,
|
|
56
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
57
|
+
"email" text NOT NULL,
|
|
58
|
+
"billing_address" jsonb NOT NULL,
|
|
59
|
+
"shipping_address" jsonb NOT NULL,
|
|
60
|
+
"line_items" jsonb NOT NULL,
|
|
61
|
+
"subtotal_minor" integer NOT NULL,
|
|
62
|
+
"tax_total_minor" integer DEFAULT 0 NOT NULL,
|
|
63
|
+
"shipping_total_minor" integer DEFAULT 0 NOT NULL,
|
|
64
|
+
"discount_total_minor" integer DEFAULT 0 NOT NULL,
|
|
65
|
+
"total_minor" integer NOT NULL,
|
|
66
|
+
"currency" text NOT NULL,
|
|
67
|
+
"notes" text DEFAULT '' NOT NULL,
|
|
68
|
+
"metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
69
|
+
"payment_intent_id" text,
|
|
70
|
+
"created_at" timestamp with time zone NOT NULL,
|
|
71
|
+
"updated_at" timestamp with time zone NOT NULL
|
|
72
|
+
);
|
|
73
|
+
--> statement-breakpoint
|
|
74
|
+
CREATE TABLE IF NOT EXISTS "product_categories" (
|
|
75
|
+
"product_id" text NOT NULL,
|
|
76
|
+
"category_id" text NOT NULL,
|
|
77
|
+
CONSTRAINT "product_categories_product_id_category_id_pk" PRIMARY KEY("product_id","category_id")
|
|
78
|
+
);
|
|
79
|
+
--> statement-breakpoint
|
|
80
|
+
CREATE TABLE IF NOT EXISTS "products" (
|
|
81
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
82
|
+
"slug" text NOT NULL,
|
|
83
|
+
"name" text NOT NULL,
|
|
84
|
+
"description" text DEFAULT '' NOT NULL,
|
|
85
|
+
"short_description" text DEFAULT '' NOT NULL,
|
|
86
|
+
"status" text DEFAULT 'draft' NOT NULL,
|
|
87
|
+
"type" text DEFAULT 'simple' NOT NULL,
|
|
88
|
+
"seo_title" text DEFAULT '' NOT NULL,
|
|
89
|
+
"seo_description" text DEFAULT '' NOT NULL,
|
|
90
|
+
"media" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
|
91
|
+
"metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
92
|
+
"created_at" timestamp with time zone NOT NULL,
|
|
93
|
+
"updated_at" timestamp with time zone NOT NULL
|
|
94
|
+
);
|
|
95
|
+
--> statement-breakpoint
|
|
96
|
+
CREATE TABLE IF NOT EXISTS "refresh_tokens" (
|
|
97
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
98
|
+
"customer_id" text NOT NULL,
|
|
99
|
+
"token_hash" text NOT NULL,
|
|
100
|
+
"revoked_at" timestamp with time zone,
|
|
101
|
+
"replaced_by_jti" text,
|
|
102
|
+
"expires_at" timestamp with time zone NOT NULL,
|
|
103
|
+
"created_at" timestamp with time zone NOT NULL
|
|
104
|
+
);
|
|
105
|
+
--> statement-breakpoint
|
|
106
|
+
CREATE TABLE IF NOT EXISTS "reviews" (
|
|
107
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
108
|
+
"product_id" text NOT NULL,
|
|
109
|
+
"customer_id" text,
|
|
110
|
+
"order_id" text,
|
|
111
|
+
"rating" integer NOT NULL,
|
|
112
|
+
"title" text DEFAULT '' NOT NULL,
|
|
113
|
+
"body" text DEFAULT '' NOT NULL,
|
|
114
|
+
"moderation_status" text DEFAULT 'pending' NOT NULL,
|
|
115
|
+
"submitted_at" timestamp with time zone NOT NULL,
|
|
116
|
+
"moderated_at" timestamp with time zone,
|
|
117
|
+
"moderated_by" text
|
|
118
|
+
);
|
|
119
|
+
--> statement-breakpoint
|
|
120
|
+
CREATE TABLE IF NOT EXISTS "stock_adjustments" (
|
|
121
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
122
|
+
"variant_id" text NOT NULL,
|
|
123
|
+
"adjustment" integer NOT NULL,
|
|
124
|
+
"reason" text NOT NULL,
|
|
125
|
+
"actor" text NOT NULL,
|
|
126
|
+
"previous_qty" integer NOT NULL,
|
|
127
|
+
"new_qty" integer NOT NULL,
|
|
128
|
+
"timestamp" timestamp with time zone NOT NULL
|
|
129
|
+
);
|
|
130
|
+
--> statement-breakpoint
|
|
131
|
+
CREATE TABLE IF NOT EXISTS "variants" (
|
|
132
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
133
|
+
"product_id" text NOT NULL,
|
|
134
|
+
"sku" text NOT NULL,
|
|
135
|
+
"name" text DEFAULT '' NOT NULL,
|
|
136
|
+
"price_minor" integer NOT NULL,
|
|
137
|
+
"compare_at_price_minor" integer,
|
|
138
|
+
"weight_grams" integer,
|
|
139
|
+
"dimensions" jsonb,
|
|
140
|
+
"stock" integer DEFAULT 0 NOT NULL,
|
|
141
|
+
"low_stock_threshold" integer DEFAULT 0 NOT NULL,
|
|
142
|
+
"options" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
|
143
|
+
"status" text DEFAULT 'active' NOT NULL,
|
|
144
|
+
"created_at" timestamp with time zone NOT NULL,
|
|
145
|
+
"updated_at" timestamp with time zone NOT NULL
|
|
146
|
+
);
|
|
147
|
+
--> statement-breakpoint
|
|
148
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "categories_slug_unique" ON "categories" USING btree ("slug");--> statement-breakpoint
|
|
149
|
+
CREATE INDEX IF NOT EXISTS "categories_parent_idx" ON "categories" USING btree ("parent_id");--> statement-breakpoint
|
|
150
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "customers_email_unique" ON "customers" USING btree ("email");--> statement-breakpoint
|
|
151
|
+
CREATE INDEX IF NOT EXISTS "inv_reservations_variant_idx" ON "inventory_reservations" USING btree ("variant_id");--> statement-breakpoint
|
|
152
|
+
CREATE INDEX IF NOT EXISTS "inv_reservations_expires_idx" ON "inventory_reservations" USING btree ("expires_at");--> statement-breakpoint
|
|
153
|
+
CREATE INDEX IF NOT EXISTS "order_history_order_idx" ON "order_history" USING btree ("order_id");--> statement-breakpoint
|
|
154
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "orders_number_unique" ON "orders" USING btree ("order_number");--> statement-breakpoint
|
|
155
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "orders_sequence_unique" ON "orders" USING btree ("sequence");--> statement-breakpoint
|
|
156
|
+
CREATE INDEX IF NOT EXISTS "orders_customer_idx" ON "orders" USING btree ("customer_id");--> statement-breakpoint
|
|
157
|
+
CREATE INDEX IF NOT EXISTS "orders_status_idx" ON "orders" USING btree ("status");--> statement-breakpoint
|
|
158
|
+
CREATE INDEX IF NOT EXISTS "product_categories_category_idx" ON "product_categories" USING btree ("category_id");--> statement-breakpoint
|
|
159
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "products_slug_unique" ON "products" USING btree ("slug");--> statement-breakpoint
|
|
160
|
+
CREATE INDEX IF NOT EXISTS "products_status_idx" ON "products" USING btree ("status");--> statement-breakpoint
|
|
161
|
+
CREATE INDEX IF NOT EXISTS "refresh_tokens_customer_idx" ON "refresh_tokens" USING btree ("customer_id");--> statement-breakpoint
|
|
162
|
+
CREATE INDEX IF NOT EXISTS "reviews_product_idx" ON "reviews" USING btree ("product_id");--> statement-breakpoint
|
|
163
|
+
CREATE INDEX IF NOT EXISTS "reviews_status_idx" ON "reviews" USING btree ("moderation_status");--> statement-breakpoint
|
|
164
|
+
CREATE INDEX IF NOT EXISTS "stock_adjustments_variant_idx" ON "stock_adjustments" USING btree ("variant_id");--> statement-breakpoint
|
|
165
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "variants_sku_unique" ON "variants" USING btree ("sku");--> statement-breakpoint
|
|
166
|
+
CREATE INDEX IF NOT EXISTS "variants_product_idx" ON "variants" USING btree ("product_id");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
CREATE INDEX IF NOT EXISTS "orders_payment_intent_idx" ON "orders" USING btree ("payment_intent_id");
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS "events" (
|
|
2
|
+
"seq" bigserial PRIMARY KEY NOT NULL,
|
|
3
|
+
"id" text NOT NULL,
|
|
4
|
+
"type" text NOT NULL,
|
|
5
|
+
"envelope" jsonb NOT NULL,
|
|
6
|
+
"created_at" timestamp with time zone NOT NULL,
|
|
7
|
+
"delivered_at" timestamp with time zone,
|
|
8
|
+
"attempts" integer DEFAULT 0 NOT NULL,
|
|
9
|
+
"dead_at" timestamp with time zone
|
|
10
|
+
);
|
|
11
|
+
--> statement-breakpoint
|
|
12
|
+
CREATE TABLE IF NOT EXISTS "processed_events" (
|
|
13
|
+
"handler_name" text NOT NULL,
|
|
14
|
+
"event_id" text NOT NULL,
|
|
15
|
+
"processed_at" timestamp with time zone NOT NULL,
|
|
16
|
+
CONSTRAINT "processed_events_handler_name_event_id_pk" PRIMARY KEY("handler_name","event_id")
|
|
17
|
+
);
|
|
18
|
+
--> statement-breakpoint
|
|
19
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "events_id_unique" ON "events" USING btree ("id");--> statement-breakpoint
|
|
20
|
+
CREATE INDEX IF NOT EXISTS "events_undelivered_idx" ON "events" USING btree ("delivered_at","seq");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS "carts" (
|
|
2
|
+
"token" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"customer_id" text,
|
|
4
|
+
"currency" text NOT NULL,
|
|
5
|
+
"items" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
|
6
|
+
"line_count" integer DEFAULT 0 NOT NULL,
|
|
7
|
+
"subtotal_minor" integer DEFAULT 0 NOT NULL,
|
|
8
|
+
"expires_at" timestamp with time zone NOT NULL,
|
|
9
|
+
"created_at" timestamp with time zone NOT NULL,
|
|
10
|
+
"updated_at" timestamp with time zone NOT NULL,
|
|
11
|
+
"abandoned_notified_at" timestamp with time zone
|
|
12
|
+
);
|
|
13
|
+
--> statement-breakpoint
|
|
14
|
+
CREATE INDEX IF NOT EXISTS "carts_expires_idx" ON "carts" USING btree ("expires_at");--> statement-breakpoint
|
|
15
|
+
CREATE INDEX IF NOT EXISTS "carts_updated_idx" ON "carts" USING btree ("updated_at");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ALTER TABLE "customers" ADD COLUMN "roles" jsonb DEFAULT '["customer"]'::jsonb NOT NULL;--> statement-breakpoint
|
|
2
|
+
-- Roles move out of free-form metadata: known roles survive, a row left with none keeps the column's ['customer'].
|
|
3
|
+
UPDATE "customers" SET "roles" = "kept"."roles"
|
|
4
|
+
FROM (
|
|
5
|
+
SELECT "c"."id", jsonb_agg(DISTINCT "r"."role") AS "roles"
|
|
6
|
+
FROM "customers" AS "c"
|
|
7
|
+
CROSS JOIN LATERAL jsonb_array_elements(
|
|
8
|
+
CASE WHEN jsonb_typeof("c"."metadata"->'roles') = 'array' THEN "c"."metadata"->'roles' ELSE '[]'::jsonb END
|
|
9
|
+
) AS "r"("role")
|
|
10
|
+
WHERE "r"."role" IN ('"admin"'::jsonb, '"customer"'::jsonb, '"guest"'::jsonb)
|
|
11
|
+
GROUP BY "c"."id"
|
|
12
|
+
) AS "kept"
|
|
13
|
+
WHERE "customers"."id" = "kept"."id";--> statement-breakpoint
|
|
14
|
+
UPDATE "customers" SET "metadata" = "metadata" - 'roles'
|
|
15
|
+
WHERE jsonb_typeof("metadata") = 'object' AND "metadata" ? 'roles';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
ALTER TABLE "orders" ADD COLUMN "cart_token" text;--> statement-breakpoint
|
|
2
|
+
-- The cart moves out of free-form metadata. Of several pending orders on one cart (made before this guard existed) only
|
|
3
|
+
-- the newest takes the token, so the index below can be built; the older ones stay as they are, without one.
|
|
4
|
+
UPDATE "orders" SET "cart_token" = "metadata"->>'cartToken'
|
|
5
|
+
WHERE jsonb_typeof("metadata"->'cartToken') = 'string' AND (
|
|
6
|
+
"status" <> 'pending' OR NOT EXISTS (
|
|
7
|
+
SELECT 1 FROM "orders" AS "newer"
|
|
8
|
+
WHERE "newer"."status" = 'pending' AND "newer"."sequence" > "orders"."sequence"
|
|
9
|
+
AND "newer"."metadata"->>'cartToken' = "orders"."metadata"->>'cartToken'
|
|
10
|
+
)
|
|
11
|
+
);--> statement-breakpoint
|
|
12
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "orders_pending_cart_unique" ON "orders" USING btree ("cart_token") WHERE status = 'pending';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS "order_refunds" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"order_id" text NOT NULL,
|
|
4
|
+
"amount_minor" integer NOT NULL,
|
|
5
|
+
"currency" text NOT NULL,
|
|
6
|
+
"provider_refund_id" text,
|
|
7
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
8
|
+
"reason" text,
|
|
9
|
+
"actor" text NOT NULL,
|
|
10
|
+
"created_at" timestamp with time zone NOT NULL,
|
|
11
|
+
"request_id" text
|
|
12
|
+
);
|
|
13
|
+
--> statement-breakpoint
|
|
14
|
+
ALTER TABLE "orders" ADD COLUMN "captured_minor" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
|
|
15
|
+
ALTER TABLE "orders" ADD COLUMN "captured_at" timestamp with time zone;--> statement-breakpoint
|
|
16
|
+
ALTER TABLE "orders" ADD COLUMN "refunded_minor" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
|
|
17
|
+
ALTER TABLE "orders" ADD COLUMN "capture_method" text;--> statement-breakpoint
|
|
18
|
+
CREATE INDEX IF NOT EXISTS "order_refunds_order_idx" ON "order_refunds" USING btree ("order_id");--> statement-breakpoint
|
|
19
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "order_refunds_order_request_idx" ON "order_refunds" USING btree ("order_id","request_id");--> statement-breakpoint
|
|
20
|
+
-- Orders taken before captures were recorded: one confirmed or later (and not cancelled) was paid in full when it last
|
|
21
|
+
-- changed; with an intent the provider took it, without one it came from an import. A partially_refunded order keeps
|
|
22
|
+
-- refunded_minor 0: what it refunded was never stored, and there is no production data from before this migration.
|
|
23
|
+
UPDATE "orders"
|
|
24
|
+
SET "captured_minor" = "total_minor",
|
|
25
|
+
"captured_at" = "updated_at",
|
|
26
|
+
"capture_method" = CASE WHEN "payment_intent_id" IS NULL THEN 'import' ELSE 'provider' END
|
|
27
|
+
WHERE "status" IN ('confirmed', 'processing', 'shipped', 'delivered', 'refunded', 'partially_refunded');--> statement-breakpoint
|
|
28
|
+
UPDATE "orders" SET "refunded_minor" = "captured_minor" WHERE "status" = 'refunded';
|