@meith/db 0.21.1 → 0.21.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meith/db",
3
- "version": "0.21.1",
3
+ "version": "0.21.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,35 +22,35 @@
22
22
  "dependencies": {
23
23
  "drizzle-orm": "^0.45.2",
24
24
  "postgres": "^3.4.7",
25
- "@meith/antispam": "0.21.1",
26
- "@meith/api": "0.21.1",
27
- "@meith/admin": "0.21.1",
28
- "@meith/accounts": "0.21.1",
29
- "@meith/attachments": "0.21.1",
30
- "@meith/authorization": "0.21.1",
31
- "@meith/avatars": "0.21.1",
32
- "@meith/core": "0.21.1",
33
- "@meith/drafts": "0.21.1",
34
- "@meith/events": "0.21.1",
35
- "@meith/forums": "0.21.1",
36
- "@meith/groups": "0.21.1",
37
- "@meith/i18n": "0.21.1",
38
- "@meith/markdown": "0.21.1",
39
- "@meith/marketplace": "0.21.1",
40
- "@meith/moderation": "0.21.1",
41
- "@meith/messages": "0.21.1",
42
- "@meith/notifications": "0.21.1",
43
- "@meith/plugin-kit": "0.21.1",
44
- "@meith/relations": "0.21.1",
45
- "@meith/polls": "0.21.1",
46
- "@meith/reputation": "0.21.1",
47
- "@meith/profile-fields": "0.21.1",
48
- "@meith/search": "0.21.1",
49
- "@meith/signatures": "0.21.1",
50
- "@meith/settings": "0.21.1",
51
- "@meith/subscriptions": "0.21.1",
52
- "@meith/tasks": "0.21.1",
53
- "@meith/threads": "0.21.1"
25
+ "@meith/accounts": "0.21.2",
26
+ "@meith/antispam": "0.21.2",
27
+ "@meith/attachments": "0.21.2",
28
+ "@meith/admin": "0.21.2",
29
+ "@meith/authorization": "0.21.2",
30
+ "@meith/api": "0.21.2",
31
+ "@meith/avatars": "0.21.2",
32
+ "@meith/drafts": "0.21.2",
33
+ "@meith/core": "0.21.2",
34
+ "@meith/events": "0.21.2",
35
+ "@meith/forums": "0.21.2",
36
+ "@meith/groups": "0.21.2",
37
+ "@meith/messages": "0.21.2",
38
+ "@meith/marketplace": "0.21.2",
39
+ "@meith/moderation": "0.21.2",
40
+ "@meith/markdown": "0.21.2",
41
+ "@meith/notifications": "0.21.2",
42
+ "@meith/polls": "0.21.2",
43
+ "@meith/plugin-kit": "0.21.2",
44
+ "@meith/profile-fields": "0.21.2",
45
+ "@meith/i18n": "0.21.2",
46
+ "@meith/relations": "0.21.2",
47
+ "@meith/reputation": "0.21.2",
48
+ "@meith/search": "0.21.2",
49
+ "@meith/settings": "0.21.2",
50
+ "@meith/signatures": "0.21.2",
51
+ "@meith/threads": "0.21.2",
52
+ "@meith/tasks": "0.21.2",
53
+ "@meith/subscriptions": "0.21.2"
54
54
  },
55
55
  "devDependencies": {
56
56
  "drizzle-kit": "^0.31.6",
package/src/index.ts CHANGED
@@ -221,6 +221,7 @@ export { PostgresReportRepository } from './report-repo'
221
221
  export { PostgresReputationRepository } from './reputation-repo'
222
222
  export { resultRows } from './result-rows'
223
223
  export * from './schema'
224
+ export { expectedTables, missingTables } from './schema-state'
224
225
  export {
225
226
  indexedSubjectSql,
226
227
  PostgresSearchRepository,
@@ -0,0 +1,22 @@
1
+ import { getTableName, is, sql } from 'drizzle-orm'
2
+ import { PgTable } from 'drizzle-orm/pg-core'
3
+
4
+ import type { Database } from './client'
5
+ import { resultRows } from './result-rows'
6
+ import * as schema from './schema'
7
+
8
+ export function expectedTables(): readonly string[] {
9
+ return Object.values(schema as Record<string, unknown>)
10
+ .filter((value) => is(value, PgTable))
11
+ .map((table) => getTableName(table as PgTable))
12
+ .sort()
13
+ }
14
+
15
+ export async function missingTables(db: Database): Promise<readonly string[]> {
16
+ const result = await db.execute(sql`
17
+ select table_name from information_schema.tables where table_schema = 'public'
18
+ `)
19
+
20
+ const present = new Set(resultRows<{ table_name: string }>(result).map((row) => row.table_name))
21
+ return expectedTables().filter((table) => !present.has(table))
22
+ }