@supersolutions/super-router-storage-postgres 0.0.0 → 0.1.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.
@@ -0,0 +1,64 @@
1
+ CREATE TABLE sr_members (
2
+ workspace text NOT NULL, environment text NOT NULL, id text NOT NULL, role text NOT NULL CHECK(role IN ('owner','service_admin','billing_admin','viewer','app')),
3
+ active boolean NOT NULL DEFAULT true, PRIMARY KEY(workspace,environment,id)
4
+ );
5
+ CREATE TABLE sr_customers (
6
+ workspace text NOT NULL, environment text NOT NULL, id text NOT NULL, external_id text NOT NULL,
7
+ PRIMARY KEY(workspace,environment,id), UNIQUE(workspace,environment,external_id)
8
+ );
9
+ CREATE TABLE sr_keys (
10
+ workspace text NOT NULL, environment text NOT NULL, id text NOT NULL, member_id text NOT NULL,
11
+ customer text NOT NULL, hash text NOT NULL UNIQUE, scopes text[] NOT NULL, service_ids text[], expires_at timestamptz NOT NULL, revoked_at timestamptz,
12
+ PRIMARY KEY(workspace,environment,id), FOREIGN KEY(workspace,environment,member_id) REFERENCES sr_members(workspace,environment,id)
13
+ );
14
+ CREATE TABLE sr_commands (
15
+ workspace text NOT NULL, environment text NOT NULL, operation text NOT NULL, key text NOT NULL, digest text NOT NULL, result jsonb NOT NULL,
16
+ PRIMARY KEY(workspace,environment,operation,key)
17
+ );
18
+ CREATE TABLE sr_audit (
19
+ id text PRIMARY KEY, workspace text NOT NULL, environment text NOT NULL, actor text NOT NULL, action text NOT NULL, resource text NOT NULL,
20
+ details jsonb NOT NULL DEFAULT '{}', created_at timestamptz NOT NULL DEFAULT now()
21
+ );
22
+ CREATE TRIGGER sr_audit_immutable BEFORE UPDATE OR DELETE ON sr_audit FOR EACH ROW EXECUTE FUNCTION sr_immutable();
23
+ CREATE TABLE sr_plans (
24
+ workspace text NOT NULL, environment text NOT NULL, id text NOT NULL, version integer NOT NULL CHECK(version>0), config jsonb NOT NULL,
25
+ PRIMARY KEY(workspace,environment,id,version)
26
+ );
27
+ CREATE TRIGGER sr_plan_immutable BEFORE UPDATE OR DELETE ON sr_plans FOR EACH ROW EXECUTE FUNCTION sr_immutable();
28
+ CREATE TABLE sr_subscriptions (
29
+ workspace text NOT NULL, environment text NOT NULL, id text NOT NULL, customer text NOT NULL, plan_id text NOT NULL, plan_version integer NOT NULL,
30
+ next_plan_id text, next_plan_version integer, anchor_at timestamptz NOT NULL, period_days integer NOT NULL CHECK(period_days>0),
31
+ status text NOT NULL DEFAULT 'pending' CHECK(status IN ('pending','active','past_due','cancelled')),
32
+ paid_cycle integer NOT NULL DEFAULT -1, current_period_end timestamptz, cancel_effective_at timestamptz,
33
+ PRIMARY KEY(workspace,environment,id),
34
+ FOREIGN KEY(workspace,environment,customer) REFERENCES sr_customers(workspace,environment,id),
35
+ FOREIGN KEY(workspace,environment,plan_id,plan_version) REFERENCES sr_plans(workspace,environment,id,version),
36
+ FOREIGN KEY(workspace,environment,next_plan_id,next_plan_version) REFERENCES sr_plans(workspace,environment,id,version)
37
+ );
38
+ CREATE TABLE sr_payment_orders (
39
+ workspace text NOT NULL, environment text NOT NULL, id text NOT NULL, subscription text NOT NULL, cycle integer NOT NULL CHECK(cycle>=0),
40
+ integration text NOT NULL, amount_minor numeric(38,0) NOT NULL CHECK(amount_minor>0), currency text NOT NULL, plan jsonb NOT NULL,
41
+ period_start timestamptz NOT NULL, period_end timestamptz NOT NULL, revision integer NOT NULL DEFAULT 0,
42
+ state text NOT NULL DEFAULT 'pending' CHECK(state IN ('pending','failed','succeeded','review_required')),
43
+ PRIMARY KEY(workspace,environment,id), UNIQUE(workspace,environment,subscription,cycle),
44
+ FOREIGN KEY(workspace,environment,subscription) REFERENCES sr_subscriptions(workspace,environment,id), CHECK(period_end>period_start)
45
+ );
46
+ CREATE TABLE sr_payment_events (
47
+ integration text NOT NULL, event_id text NOT NULL, workspace text NOT NULL, environment text NOT NULL, order_id text NOT NULL,
48
+ digest text NOT NULL, outcome text NOT NULL, created_at timestamptz NOT NULL DEFAULT now(), PRIMARY KEY(integration,event_id),
49
+ FOREIGN KEY(workspace,environment,order_id) REFERENCES sr_payment_orders(workspace,environment,id)
50
+ );
51
+ CREATE TRIGGER sr_payment_event_immutable BEFORE UPDATE OR DELETE ON sr_payment_events FOR EACH ROW EXECUTE FUNCTION sr_immutable();
52
+ CREATE TABLE sr_entitlements (
53
+ workspace text NOT NULL, environment text NOT NULL, subscription text NOT NULL, cycle integer NOT NULL, customer text NOT NULL,
54
+ service_ids text[] NOT NULL, period_start timestamptz NOT NULL, period_end timestamptz NOT NULL, bucket text NOT NULL,
55
+ PRIMARY KEY(workspace,environment,subscription,cycle),
56
+ FOREIGN KEY(workspace,environment,subscription) REFERENCES sr_subscriptions(workspace,environment,id),
57
+ FOREIGN KEY(workspace,environment,bucket) REFERENCES sr_buckets(workspace,environment,id)
58
+ );
59
+ CREATE TRIGGER sr_entitlement_immutable BEFORE UPDATE OR DELETE ON sr_entitlements FOR EACH ROW EXECUTE FUNCTION sr_immutable();
60
+ ALTER TABLE sr_buckets ADD COLUMN source_kind text NOT NULL DEFAULT 'purchased' CHECK(source_kind IN ('subscription','promotion','purchased'));
61
+ ALTER TABLE sr_buckets ADD COLUMN service_ids text[];
62
+ CREATE INDEX sr_entitlement_customer_period ON sr_entitlements(workspace,environment,customer,period_end);
63
+ CREATE INDEX sr_subscriptions_due ON sr_subscriptions(status,current_period_end);
64
+ CREATE INDEX sr_audit_tenant ON sr_audit(workspace,environment,created_at,id);
@@ -0,0 +1,4 @@
1
+ CREATE TABLE sr_integration_bindings (
2
+ id text PRIMARY KEY, workspace text NOT NULL, environment text NOT NULL
3
+ );
4
+ CREATE TRIGGER sr_integration_binding_immutable BEFORE UPDATE OR DELETE ON sr_integration_bindings FOR EACH ROW EXECUTE FUNCTION sr_immutable();
@@ -0,0 +1,9 @@
1
+ CREATE TABLE sr_checkouts (
2
+ workspace text NOT NULL, environment text NOT NULL, order_id text NOT NULL,
3
+ integration text NOT NULL, identity text NOT NULL,
4
+ state text NOT NULL CHECK(state IN ('creating','ready','unknown')),
5
+ reference text, url text, created_at timestamptz NOT NULL DEFAULT now(),
6
+ PRIMARY KEY(workspace,environment,order_id),
7
+ UNIQUE(integration,reference),
8
+ FOREIGN KEY(workspace,environment,order_id) REFERENCES sr_payment_orders(workspace,environment,id)
9
+ );
package/package.json CHANGED
@@ -1,16 +1,40 @@
1
1
  {
2
2
  "name": "@supersolutions/super-router-storage-postgres",
3
- "version": "0.0.0",
4
- "description": "Placeholder; real releases come from GitHub Actions.",
3
+ "version": "0.1.0",
5
4
  "license": "Apache-2.0",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/Super-Solution/super-router.git"
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ }
9
11
  },
10
12
  "files": [
11
- "README.md"
13
+ "dist",
14
+ "migrations",
15
+ "LICENSE",
16
+ "NOTICE"
12
17
  ],
18
+ "scripts": {
19
+ "build": "tsc -p tsconfig.json"
20
+ },
21
+ "dependencies": {
22
+ "@supersolutions/super-router-contracts": "0.1.0",
23
+ "pg": "8.23.1",
24
+ "@supersolutions/super-router-core": "0.1.0",
25
+ "@supersolutions/super-router-payments": "0.1.0"
26
+ },
27
+ "author": "SUPER SOLUTION LABS INC",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/Super-Solution/super-router.git",
31
+ "directory": "packages/adapters/storage-postgres"
32
+ },
33
+ "homepage": "https://github.com/Super-Solution/super-router#readme",
34
+ "bugs": {
35
+ "url": "https://github.com/Super-Solution/super-router/issues"
36
+ },
13
37
  "publishConfig": {
14
38
  "access": "public"
15
39
  }
16
- }
40
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # @supersolutions/super-router-storage-postgres
2
-
3
- Placeholder. Releases are published from https://github.com/Super-Solution/super-router by GitHub Actions.