@brandtg/flapjack 1.3.0 → 1.5.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,93 @@
1
+ /**
2
+ * @type {import('node-pg-migrate').ColumnDefinitions | undefined}
3
+ */
4
+ export const shorthands = undefined;
5
+
6
+ /**
7
+ * @param pgm {import('node-pg-migrate').MigrationBuilder}
8
+ * @param run {() => void | undefined}
9
+ * @returns {Promise<void> | void}
10
+ */
11
+ export const up = (pgm) => {
12
+ pgm.createTable(
13
+ { schema: "flapjack", name: "feature_flag_subject" },
14
+ {
15
+ id: "id",
16
+ feature_flag_id: {
17
+ type: "integer",
18
+ notNull: true,
19
+ references: { schema: "flapjack", name: "feature_flag" },
20
+ onDelete: "CASCADE",
21
+ },
22
+ subject: { type: "text", notNull: true },
23
+ created: {
24
+ type: "timestamptz",
25
+ notNull: true,
26
+ default: pgm.func("now()"),
27
+ },
28
+ },
29
+ );
30
+
31
+ pgm.addConstraint(
32
+ { schema: "flapjack", name: "feature_flag_subject" },
33
+ "unique_feature_flag_subject",
34
+ {
35
+ unique: ["feature_flag_id", "subject"],
36
+ },
37
+ );
38
+
39
+ pgm.createIndex(
40
+ { schema: "flapjack", name: "feature_flag_subject" },
41
+ "feature_flag_id",
42
+ );
43
+ pgm.createIndex(
44
+ { schema: "flapjack", name: "feature_flag_subject" },
45
+ "subject",
46
+ );
47
+
48
+ pgm.createTable(
49
+ { schema: "flapjack", name: "feature_flag_group_subject" },
50
+ {
51
+ id: "id",
52
+ feature_flag_group_id: {
53
+ type: "integer",
54
+ notNull: true,
55
+ references: { schema: "flapjack", name: "feature_flag_group" },
56
+ onDelete: "CASCADE",
57
+ },
58
+ subject: { type: "text", notNull: true },
59
+ created: {
60
+ type: "timestamptz",
61
+ notNull: true,
62
+ default: pgm.func("now()"),
63
+ },
64
+ },
65
+ );
66
+
67
+ pgm.addConstraint(
68
+ { schema: "flapjack", name: "feature_flag_group_subject" },
69
+ "unique_feature_flag_group_subject",
70
+ {
71
+ unique: ["feature_flag_group_id", "subject"],
72
+ },
73
+ );
74
+
75
+ pgm.createIndex(
76
+ { schema: "flapjack", name: "feature_flag_group_subject" },
77
+ "feature_flag_group_id",
78
+ );
79
+ pgm.createIndex(
80
+ { schema: "flapjack", name: "feature_flag_group_subject" },
81
+ "subject",
82
+ );
83
+ };
84
+
85
+ /**
86
+ * @param pgm {import('node-pg-migrate').MigrationBuilder}
87
+ * @param run {() => void | undefined}
88
+ * @returns {Promise<void> | void}
89
+ */
90
+ export const down = (pgm) => {
91
+ pgm.dropTable({ schema: "flapjack", name: "feature_flag_group_subject" });
92
+ pgm.dropTable({ schema: "flapjack", name: "feature_flag_subject" });
93
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @type {import('node-pg-migrate').ColumnDefinitions | undefined}
3
+ */
4
+ export const shorthands = undefined;
5
+
6
+ /**
7
+ * @param pgm {import('node-pg-migrate').MigrationBuilder}
8
+ * @param run {() => void | undefined}
9
+ * @returns {Promise<void> | void}
10
+ */
11
+ export const up = (pgm) => {
12
+ pgm.addColumn(
13
+ { schema: "flapjack", name: "feature_flag" },
14
+ {
15
+ tags: {
16
+ type: "text[]",
17
+ default: pgm.func("'{}'::text[]"),
18
+ },
19
+ },
20
+ );
21
+
22
+ // GIN index for efficient lookups by tag (e.g. WHERE $1 = ANY(tags))
23
+ pgm.createIndex({ schema: "flapjack", name: "feature_flag" }, "tags", {
24
+ method: "gin",
25
+ });
26
+ };
27
+
28
+ /**
29
+ * @param pgm {import('node-pg-migrate').MigrationBuilder}
30
+ * @param run {() => void | undefined}
31
+ * @returns {Promise<void> | void}
32
+ */
33
+ export const down = (pgm) => {
34
+ pgm.dropIndex({ schema: "flapjack", name: "feature_flag" }, "tags", {
35
+ method: "gin",
36
+ });
37
+ pgm.dropColumn({ schema: "flapjack", name: "feature_flag" }, "tags");
38
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @type {import('node-pg-migrate').ColumnDefinitions | undefined}
3
+ */
4
+ export const shorthands = undefined;
5
+
6
+ /**
7
+ * @param pgm {import('node-pg-migrate').MigrationBuilder}
8
+ * @param run {() => void | undefined}
9
+ * @returns {Promise<void> | void}
10
+ */
11
+ export const up = (pgm) => {
12
+ // Add a nullable archived timestamp to the core data models. When set, the
13
+ // record is considered archived (hidden) but kept for historical/audit
14
+ // purposes. Archiving is irreversible and the name remains reserved forever
15
+ // (the existing UNIQUE(name) constraint is intentionally left unchanged).
16
+ pgm.addColumn(
17
+ { schema: "flapjack", name: "feature_flag" },
18
+ { archived: { type: "timestamptz" } },
19
+ );
20
+ pgm.addColumn(
21
+ { schema: "flapjack", name: "feature_flag_group" },
22
+ { archived: { type: "timestamptz" } },
23
+ );
24
+ };
25
+
26
+ /**
27
+ * @param pgm {import('node-pg-migrate').MigrationBuilder}
28
+ * @param run {() => void | undefined}
29
+ * @returns {Promise<void> | void}
30
+ */
31
+ export const down = (pgm) => {
32
+ pgm.dropColumn({ schema: "flapjack", name: "feature_flag" }, "archived");
33
+ pgm.dropColumn(
34
+ { schema: "flapjack", name: "feature_flag_group" },
35
+ "archived",
36
+ );
37
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brandtg/flapjack",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "A simple feature flags library with PostgreSQL integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "clean": "rm -rf dist",
28
28
  "dev": "npx tsc --watch",
29
29
  "dev:env": "bash bin/dev/env.sh",
30
- "dev:migrate": "npx dotenv-cli -e env -- node-pg-migrate up",
30
+ "dev:migrate": "npx dotenv-cli -e .env -- node-pg-migrate up -s flapjack --create-schema -t pgmigrations",
31
31
  "dev:docker:up": "docker compose -f docker-compose.yml up -d",
32
32
  "dev:docker:down": "docker compose -f docker-compose.yml down -v",
33
33
  "create-migration": "npx node-pg-migrate create --",