@aopslab/domain-pg-bootstrap-docman 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.
- package/LICENSE +202 -0
- package/NOTICE +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/pg-bootstrap.d.ts +13 -0
- package/dist/pg-bootstrap.js +240 -0
- package/drizzle-out/docman/0000_curvy_valeria_richards.sql +257 -0
- package/drizzle-out/docman/0001_massive_risque.sql +2 -0
- package/drizzle-out/docman/0002_simple_logan.sql +50 -0
- package/drizzle-out/docman/0003_quick_index.sql +45 -0
- package/drizzle-out/docman/0004_known_summary.sql +9 -0
- package/drizzle-out/docman/0005_vector_signal.sql +9 -0
- package/drizzle-out/docman/0006_document_version_current_invariant.sql +15 -0
- package/drizzle-out/docman/meta/_journal.json +55 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pg-bootstrap.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pg-bootstrap.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type DocmanPgBootstrapPaths = {
|
|
2
|
+
domainRoot: string;
|
|
3
|
+
migrationsDir: string;
|
|
4
|
+
migrationsDirExists: boolean;
|
|
5
|
+
journalPath: string;
|
|
6
|
+
journalExists: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function resolveDocmanPgBootstrapPaths(domainRoot?: string): DocmanPgBootstrapPaths;
|
|
9
|
+
export declare function applyDocmanPgSchema(params: {
|
|
10
|
+
repoUrl: string;
|
|
11
|
+
domainRoot?: string;
|
|
12
|
+
logs?: string[];
|
|
13
|
+
}): Promise<DocmanPgBootstrapPaths>;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { Client } from 'pg';
|
|
5
|
+
const STATEMENT_BREAKPOINT = '--> statement-breakpoint';
|
|
6
|
+
const MIGRATION_TABLE = 'docman_schema_migrations';
|
|
7
|
+
const TRACKED_TABLES = [
|
|
8
|
+
'docman_documents',
|
|
9
|
+
'docman_document_groups',
|
|
10
|
+
'docman_document_versions',
|
|
11
|
+
'docman_sections',
|
|
12
|
+
'docman_pages',
|
|
13
|
+
'docman_page_versions',
|
|
14
|
+
'docman_document_index_entries',
|
|
15
|
+
'docman_document_section_links',
|
|
16
|
+
'docman_section_page_links',
|
|
17
|
+
'docman_snippets',
|
|
18
|
+
'docman_page_snippet_links',
|
|
19
|
+
'docman_assets',
|
|
20
|
+
'docman_asset_versions',
|
|
21
|
+
'docman_embeds',
|
|
22
|
+
'docman_page_embed_links',
|
|
23
|
+
];
|
|
24
|
+
function resolveDocmanDomainRoot(domainRoot) {
|
|
25
|
+
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
26
|
+
const explicitDomainRoot = domainRoot ? path.resolve(domainRoot) : null;
|
|
27
|
+
const explicitWorkspaceDomainRoots = explicitDomainRoot
|
|
28
|
+
? [path.join(explicitDomainRoot, 'domains', 'docman'), path.join(explicitDomainRoot, 'docman')]
|
|
29
|
+
: [];
|
|
30
|
+
const workspaceDomainRoot = path.resolve(packageRoot, '..');
|
|
31
|
+
const candidates = [packageRoot, explicitDomainRoot, ...explicitWorkspaceDomainRoots, workspaceDomainRoot];
|
|
32
|
+
for (const candidate of candidates) {
|
|
33
|
+
if (candidate && existsSync(path.join(candidate, 'drizzle-out', 'docman'))) {
|
|
34
|
+
return candidate;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return packageRoot;
|
|
38
|
+
}
|
|
39
|
+
export function resolveDocmanPgBootstrapPaths(domainRoot) {
|
|
40
|
+
const resolvedDomainRoot = resolveDocmanDomainRoot(domainRoot);
|
|
41
|
+
const migrationsDir = path.join(resolvedDomainRoot, 'drizzle-out', 'docman');
|
|
42
|
+
const journalPath = path.join(migrationsDir, 'meta', '_journal.json');
|
|
43
|
+
return {
|
|
44
|
+
domainRoot: resolvedDomainRoot,
|
|
45
|
+
migrationsDir,
|
|
46
|
+
migrationsDirExists: existsSync(migrationsDir),
|
|
47
|
+
journalPath,
|
|
48
|
+
journalExists: existsSync(journalPath),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function splitMigrationStatements(sql) {
|
|
52
|
+
return sql
|
|
53
|
+
.split(STATEMENT_BREAKPOINT)
|
|
54
|
+
.map((statement) => statement.trim())
|
|
55
|
+
.filter(Boolean);
|
|
56
|
+
}
|
|
57
|
+
function readMigrationJournal(paths) {
|
|
58
|
+
if (!paths.journalExists) {
|
|
59
|
+
throw new Error(`docman_pg_bootstrap_journal_missing:${paths.journalPath}`);
|
|
60
|
+
}
|
|
61
|
+
const payload = JSON.parse(readFileSync(paths.journalPath, 'utf8'));
|
|
62
|
+
const entries = Array.isArray(payload.entries) ? payload.entries : [];
|
|
63
|
+
return entries
|
|
64
|
+
.map((entry) => ({
|
|
65
|
+
idx: Number(entry.idx ?? 0),
|
|
66
|
+
tag: String(entry.tag ?? '').trim(),
|
|
67
|
+
}))
|
|
68
|
+
.filter((entry) => entry.tag.length > 0)
|
|
69
|
+
.sort((left, right) => left.idx - right.idx);
|
|
70
|
+
}
|
|
71
|
+
function resolveMigrationSqlPath(paths, tag) {
|
|
72
|
+
return path.join(paths.migrationsDir, `${tag}.sql`);
|
|
73
|
+
}
|
|
74
|
+
async function withPgClient(repoUrl, fn) {
|
|
75
|
+
const client = new Client({ connectionString: repoUrl });
|
|
76
|
+
await client.connect();
|
|
77
|
+
try {
|
|
78
|
+
return await fn(client);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
await client.end().catch(() => undefined);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function ensureMigrationTable(client) {
|
|
85
|
+
await client.query(`CREATE TABLE IF NOT EXISTS public.${MIGRATION_TABLE} (
|
|
86
|
+
tag text PRIMARY KEY,
|
|
87
|
+
applied_at timestamp with time zone NOT NULL DEFAULT now()
|
|
88
|
+
)`);
|
|
89
|
+
}
|
|
90
|
+
async function readAppliedTags(client) {
|
|
91
|
+
const result = await client.query(`SELECT tag FROM public.${MIGRATION_TABLE}`);
|
|
92
|
+
return new Set(result.rows.map((row) => row.tag));
|
|
93
|
+
}
|
|
94
|
+
async function queryExistingTables(client) {
|
|
95
|
+
const result = await client.query(`SELECT table_name
|
|
96
|
+
FROM information_schema.tables
|
|
97
|
+
WHERE table_schema = 'public'
|
|
98
|
+
AND table_name = ANY($1::text[])`, [TRACKED_TABLES]);
|
|
99
|
+
return new Set(result.rows.map((row) => row.table_name));
|
|
100
|
+
}
|
|
101
|
+
async function hasColumn(client, tableName, columnName, expectedType) {
|
|
102
|
+
const result = await client.query(`SELECT data_type, udt_name
|
|
103
|
+
FROM information_schema.columns
|
|
104
|
+
WHERE table_schema = 'public'
|
|
105
|
+
AND table_name = $1
|
|
106
|
+
AND column_name = $2`, [tableName, columnName]);
|
|
107
|
+
const row = result.rows[0];
|
|
108
|
+
if (!row)
|
|
109
|
+
return false;
|
|
110
|
+
if (!expectedType)
|
|
111
|
+
return true;
|
|
112
|
+
return row.data_type === expectedType || row.udt_name === expectedType;
|
|
113
|
+
}
|
|
114
|
+
async function lacksColumn(client, tableName, columnName) {
|
|
115
|
+
const result = await client.query(`SELECT COUNT(*)::text AS count
|
|
116
|
+
FROM information_schema.columns
|
|
117
|
+
WHERE table_schema = 'public'
|
|
118
|
+
AND table_name = $1
|
|
119
|
+
AND column_name = $2`, [tableName, columnName]);
|
|
120
|
+
return String(result.rows[0]?.count ?? '0') === '0';
|
|
121
|
+
}
|
|
122
|
+
async function schemaLooksCurrent(client) {
|
|
123
|
+
const existingTables = await queryExistingTables(client);
|
|
124
|
+
if (existingTables.size !== TRACKED_TABLES.length) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
const checks = [
|
|
128
|
+
() => hasColumn(client, 'docman_documents', 'scopeId', 'uuid'),
|
|
129
|
+
() => hasColumn(client, 'docman_document_groups', 'scopeId', 'uuid'),
|
|
130
|
+
() => hasColumn(client, 'docman_sections', 'scopeId', 'uuid'),
|
|
131
|
+
() => hasColumn(client, 'docman_pages', 'scopeId', 'uuid'),
|
|
132
|
+
() => hasColumn(client, 'docman_snippets', 'scopeId', 'uuid'),
|
|
133
|
+
() => hasColumn(client, 'docman_embeds', 'scopeId', 'uuid'),
|
|
134
|
+
() => hasColumn(client, 'docman_assets', 'scopeId', 'uuid'),
|
|
135
|
+
() => hasColumn(client, 'docman_documents', 'titleMl', 'jsonb'),
|
|
136
|
+
() => hasColumn(client, 'docman_document_versions', 'releaseNotesMl', 'jsonb'),
|
|
137
|
+
() => hasColumn(client, 'docman_page_versions', 'contentData', 'jsonb'),
|
|
138
|
+
() => hasColumn(client, 'docman_document_index_entries', 'searchText', 'text'),
|
|
139
|
+
() => hasColumn(client, 'docman_document_index_entries', 'summaryText', 'text'),
|
|
140
|
+
() => hasColumn(client, 'docman_document_index_entries', 'sourceCharCount', 'int4'),
|
|
141
|
+
() => hasColumn(client, 'docman_document_index_entries', 'sourceWordCount', 'int4'),
|
|
142
|
+
() => hasColumn(client, 'docman_document_index_entries', 'summaryCharCount', 'int4'),
|
|
143
|
+
() => hasColumn(client, 'docman_document_index_entries', 'summaryWordCount', 'int4'),
|
|
144
|
+
() => hasColumn(client, 'docman_document_index_entries', 'embeddingProvider', 'text'),
|
|
145
|
+
() => hasColumn(client, 'docman_document_index_entries', 'embeddingModel', 'text'),
|
|
146
|
+
() => hasColumn(client, 'docman_document_index_entries', 'embeddingHash', 'text'),
|
|
147
|
+
() => hasColumn(client, 'docman_document_index_entries', 'embeddingDimensions', 'int4'),
|
|
148
|
+
() => hasColumn(client, 'docman_document_index_entries', 'embeddingVector', 'text'),
|
|
149
|
+
() => hasColumn(client, 'docman_document_section_links', 'directives', 'jsonb'),
|
|
150
|
+
() => hasColumn(client, 'docman_page_snippet_links', 'showLineNumbers'),
|
|
151
|
+
() => hasColumn(client, 'docman_assets', 'currentVersionId', 'uuid'),
|
|
152
|
+
() => hasColumn(client, 'docman_asset_versions', 'contentHash', 'text'),
|
|
153
|
+
() => lacksColumn(client, 'docman_sections', 'description'),
|
|
154
|
+
() => lacksColumn(client, 'docman_sections', 'descriptionMl'),
|
|
155
|
+
];
|
|
156
|
+
for (const check of checks) {
|
|
157
|
+
if (!(await check()))
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
async function adoptExistingCurrentSchema(client, missingEntries, logs) {
|
|
163
|
+
if (missingEntries.length === 0)
|
|
164
|
+
return true;
|
|
165
|
+
const looksCurrent = await schemaLooksCurrent(client);
|
|
166
|
+
if (!looksCurrent)
|
|
167
|
+
return false;
|
|
168
|
+
logs.push('Existing docman PostgreSQL schema detected without complete migration journal. Adopting current schema state.');
|
|
169
|
+
for (const entry of missingEntries) {
|
|
170
|
+
await client.query(`INSERT INTO public.${MIGRATION_TABLE} (tag) VALUES ($1) ON CONFLICT (tag) DO NOTHING`, [entry.tag]);
|
|
171
|
+
}
|
|
172
|
+
logs.push(`Adopted ${String(missingEntries.length)} migration tag(s) without reapplying SQL.`);
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
async function applyMigrationEntry(client, paths, entry, logs) {
|
|
176
|
+
const sqlPath = resolveMigrationSqlPath(paths, entry.tag);
|
|
177
|
+
if (!existsSync(sqlPath)) {
|
|
178
|
+
throw new Error(`docman_pg_bootstrap_sql_missing:${sqlPath}`);
|
|
179
|
+
}
|
|
180
|
+
const sql = readFileSync(sqlPath, 'utf8');
|
|
181
|
+
const statements = splitMigrationStatements(sql);
|
|
182
|
+
if (statements.length === 0) {
|
|
183
|
+
logs.push(`Skipping ${entry.tag}: migration file contains no executable statements.`);
|
|
184
|
+
await client.query(`INSERT INTO public.${MIGRATION_TABLE} (tag) VALUES ($1) ON CONFLICT (tag) DO NOTHING`, [entry.tag]);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
logs.push(`Applying Docman PostgreSQL migration: ${entry.tag}`);
|
|
188
|
+
await client.query('BEGIN');
|
|
189
|
+
try {
|
|
190
|
+
for (const statement of statements) {
|
|
191
|
+
await client.query(statement);
|
|
192
|
+
}
|
|
193
|
+
await client.query(`INSERT INTO public.${MIGRATION_TABLE} (tag) VALUES ($1) ON CONFLICT (tag) DO NOTHING`, [entry.tag]);
|
|
194
|
+
await client.query('COMMIT');
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
await client.query('ROLLBACK').catch(() => undefined);
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async function assertSchemaMatchesAppliedMigrations(client, entries) {
|
|
202
|
+
const appliedTags = await readAppliedTags(client);
|
|
203
|
+
const hasFullJournal = entries.every((entry) => appliedTags.has(entry.tag));
|
|
204
|
+
if (!hasFullJournal)
|
|
205
|
+
return;
|
|
206
|
+
const looksCurrent = await schemaLooksCurrent(client);
|
|
207
|
+
if (looksCurrent)
|
|
208
|
+
return;
|
|
209
|
+
throw new Error('docman_pg_bootstrap_schema_drift_detected:all_migrations_marked_applied_but_schema_is_incomplete');
|
|
210
|
+
}
|
|
211
|
+
export async function applyDocmanPgSchema(params) {
|
|
212
|
+
const logs = params.logs ?? [];
|
|
213
|
+
const paths = resolveDocmanPgBootstrapPaths(params.domainRoot);
|
|
214
|
+
if (!paths.migrationsDirExists) {
|
|
215
|
+
throw new Error(`docman_pg_bootstrap_migrations_dir_missing:${paths.migrationsDir}`);
|
|
216
|
+
}
|
|
217
|
+
const entries = readMigrationJournal(paths);
|
|
218
|
+
logs.push('Applying Docman PostgreSQL schema via owned SQL migration runner...');
|
|
219
|
+
await withPgClient(params.repoUrl, async (client) => {
|
|
220
|
+
await client.query('CREATE EXTENSION IF NOT EXISTS pgcrypto');
|
|
221
|
+
await ensureMigrationTable(client);
|
|
222
|
+
await assertSchemaMatchesAppliedMigrations(client, entries);
|
|
223
|
+
let appliedTags = await readAppliedTags(client);
|
|
224
|
+
const missingEntries = entries.filter((entry) => !appliedTags.has(entry.tag));
|
|
225
|
+
const adopted = await adoptExistingCurrentSchema(client, missingEntries, logs);
|
|
226
|
+
if (adopted) {
|
|
227
|
+
appliedTags = await readAppliedTags(client);
|
|
228
|
+
}
|
|
229
|
+
for (const entry of entries) {
|
|
230
|
+
if (appliedTags.has(entry.tag)) {
|
|
231
|
+
logs.push(`Skipping ${entry.tag}: already applied.`);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
await applyMigrationEntry(client, paths, entry, logs);
|
|
235
|
+
appliedTags.add(entry.tag);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
logs.push('Docman PostgreSQL schema is ready.');
|
|
239
|
+
return paths;
|
|
240
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
CREATE TABLE "docman_documents" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"tenantId" text NOT NULL,
|
|
4
|
+
"scopeId" uuid NOT NULL,
|
|
5
|
+
"documentUid" text NOT NULL,
|
|
6
|
+
"groupId" uuid,
|
|
7
|
+
"groupUid" text,
|
|
8
|
+
"slug" text,
|
|
9
|
+
"title" text NOT NULL,
|
|
10
|
+
"titleMl" jsonb,
|
|
11
|
+
"summary" text,
|
|
12
|
+
"summaryMl" jsonb,
|
|
13
|
+
"description" text,
|
|
14
|
+
"descriptionMl" jsonb,
|
|
15
|
+
"status" text NOT NULL,
|
|
16
|
+
"visibility" text NOT NULL,
|
|
17
|
+
"tags" jsonb,
|
|
18
|
+
"pageSize" text,
|
|
19
|
+
"meta" jsonb,
|
|
20
|
+
"createdBy" text,
|
|
21
|
+
"updatedBy" text,
|
|
22
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
23
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
24
|
+
);
|
|
25
|
+
--> statement-breakpoint
|
|
26
|
+
CREATE TABLE "docman_document_groups" (
|
|
27
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
28
|
+
"tenantId" text NOT NULL,
|
|
29
|
+
"scopeId" uuid NOT NULL,
|
|
30
|
+
"groupUid" text NOT NULL,
|
|
31
|
+
"parentGroupId" uuid,
|
|
32
|
+
"parentGroupUid" text,
|
|
33
|
+
"title" text NOT NULL,
|
|
34
|
+
"description" text,
|
|
35
|
+
"meta" jsonb,
|
|
36
|
+
"createdBy" text,
|
|
37
|
+
"updatedBy" text,
|
|
38
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
39
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
40
|
+
);
|
|
41
|
+
--> statement-breakpoint
|
|
42
|
+
CREATE TABLE "docman_document_versions" (
|
|
43
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
44
|
+
"tenantId" text NOT NULL,
|
|
45
|
+
"documentId" uuid NOT NULL,
|
|
46
|
+
"version" integer NOT NULL,
|
|
47
|
+
"label" text,
|
|
48
|
+
"status" text NOT NULL,
|
|
49
|
+
"title" text,
|
|
50
|
+
"summary" text,
|
|
51
|
+
"releaseNotes" text,
|
|
52
|
+
"releaseNotesMl" jsonb,
|
|
53
|
+
"isCurrent" boolean DEFAULT false NOT NULL,
|
|
54
|
+
"basedOnVersionId" uuid,
|
|
55
|
+
"publishedAt" timestamp with time zone,
|
|
56
|
+
"createdBy" text,
|
|
57
|
+
"updatedBy" text,
|
|
58
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
59
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
60
|
+
);
|
|
61
|
+
--> statement-breakpoint
|
|
62
|
+
CREATE TABLE "docman_sections" (
|
|
63
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
64
|
+
"tenantId" text NOT NULL,
|
|
65
|
+
"scopeId" uuid NOT NULL,
|
|
66
|
+
"sectionUid" text NOT NULL,
|
|
67
|
+
"title" text NOT NULL,
|
|
68
|
+
"titleMl" jsonb,
|
|
69
|
+
"description" text,
|
|
70
|
+
"descriptionMl" jsonb,
|
|
71
|
+
"kind" text,
|
|
72
|
+
"slug" text,
|
|
73
|
+
"createdBy" text,
|
|
74
|
+
"updatedBy" text,
|
|
75
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
76
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
77
|
+
);
|
|
78
|
+
--> statement-breakpoint
|
|
79
|
+
CREATE TABLE "docman_pages" (
|
|
80
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
81
|
+
"tenantId" text NOT NULL,
|
|
82
|
+
"scopeId" uuid NOT NULL,
|
|
83
|
+
"pageUid" text NOT NULL,
|
|
84
|
+
"title" text NOT NULL,
|
|
85
|
+
"titleMl" jsonb,
|
|
86
|
+
"kind" text,
|
|
87
|
+
"meta" jsonb,
|
|
88
|
+
"createdBy" text,
|
|
89
|
+
"updatedBy" text,
|
|
90
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
91
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
92
|
+
);
|
|
93
|
+
--> statement-breakpoint
|
|
94
|
+
CREATE TABLE "docman_page_versions" (
|
|
95
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
96
|
+
"tenantId" text NOT NULL,
|
|
97
|
+
"pageId" uuid NOT NULL,
|
|
98
|
+
"version" integer NOT NULL,
|
|
99
|
+
"title" text,
|
|
100
|
+
"format" text NOT NULL,
|
|
101
|
+
"content" text,
|
|
102
|
+
"contentMl" jsonb,
|
|
103
|
+
"contentData" jsonb,
|
|
104
|
+
"directives" jsonb,
|
|
105
|
+
"status" text NOT NULL,
|
|
106
|
+
"createdBy" text,
|
|
107
|
+
"updatedBy" text,
|
|
108
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
109
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
110
|
+
);
|
|
111
|
+
--> statement-breakpoint
|
|
112
|
+
CREATE TABLE "docman_document_section_links" (
|
|
113
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
114
|
+
"tenantId" text NOT NULL,
|
|
115
|
+
"documentVersionId" uuid NOT NULL,
|
|
116
|
+
"kind" text NOT NULL,
|
|
117
|
+
"sectionId" uuid,
|
|
118
|
+
"pageVersionId" uuid,
|
|
119
|
+
"parentLinkId" uuid,
|
|
120
|
+
"position" integer NOT NULL,
|
|
121
|
+
"depth" integer,
|
|
122
|
+
"titleOverride" text,
|
|
123
|
+
"titleVisible" boolean DEFAULT true NOT NULL,
|
|
124
|
+
"numbering" text,
|
|
125
|
+
"pageBreakBefore" boolean DEFAULT false NOT NULL,
|
|
126
|
+
"pageBreakAfter" boolean DEFAULT false NOT NULL,
|
|
127
|
+
"directives" jsonb,
|
|
128
|
+
"createdBy" text,
|
|
129
|
+
"updatedBy" text,
|
|
130
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
131
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
132
|
+
);
|
|
133
|
+
--> statement-breakpoint
|
|
134
|
+
CREATE TABLE "docman_section_page_links" (
|
|
135
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
136
|
+
"tenantId" text NOT NULL,
|
|
137
|
+
"sectionId" uuid NOT NULL,
|
|
138
|
+
"pageVersionId" uuid NOT NULL,
|
|
139
|
+
"position" integer NOT NULL,
|
|
140
|
+
"numbering" text,
|
|
141
|
+
"titleOverride" text,
|
|
142
|
+
"titleVisible" boolean DEFAULT true NOT NULL,
|
|
143
|
+
"pageBreakBefore" boolean DEFAULT false NOT NULL,
|
|
144
|
+
"pageBreakAfter" boolean DEFAULT false NOT NULL,
|
|
145
|
+
"createdBy" text,
|
|
146
|
+
"updatedBy" text,
|
|
147
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
148
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
149
|
+
);
|
|
150
|
+
--> statement-breakpoint
|
|
151
|
+
CREATE TABLE "docman_snippets" (
|
|
152
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
153
|
+
"tenantId" text NOT NULL,
|
|
154
|
+
"scopeId" uuid NOT NULL,
|
|
155
|
+
"snippetUid" text NOT NULL,
|
|
156
|
+
"title" text,
|
|
157
|
+
"language" text NOT NULL,
|
|
158
|
+
"code" text NOT NULL,
|
|
159
|
+
"description" text,
|
|
160
|
+
"meta" jsonb,
|
|
161
|
+
"createdBy" text,
|
|
162
|
+
"updatedBy" text,
|
|
163
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
164
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
165
|
+
);
|
|
166
|
+
--> statement-breakpoint
|
|
167
|
+
CREATE TABLE "docman_page_snippet_links" (
|
|
168
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
169
|
+
"tenantId" text NOT NULL,
|
|
170
|
+
"pageVersionId" uuid NOT NULL,
|
|
171
|
+
"snippetId" uuid NOT NULL,
|
|
172
|
+
"position" integer NOT NULL,
|
|
173
|
+
"caption" text,
|
|
174
|
+
"showLineNumbers" boolean,
|
|
175
|
+
"createdBy" text,
|
|
176
|
+
"updatedBy" text,
|
|
177
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
178
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
179
|
+
);
|
|
180
|
+
--> statement-breakpoint
|
|
181
|
+
CREATE TABLE "docman_embeds" (
|
|
182
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
183
|
+
"tenantId" text NOT NULL,
|
|
184
|
+
"scopeId" uuid NOT NULL,
|
|
185
|
+
"embedUid" text NOT NULL,
|
|
186
|
+
"type" text NOT NULL,
|
|
187
|
+
"title" text,
|
|
188
|
+
"content" text,
|
|
189
|
+
"url" text,
|
|
190
|
+
"path" text,
|
|
191
|
+
"mime" text,
|
|
192
|
+
"meta" jsonb,
|
|
193
|
+
"createdBy" text,
|
|
194
|
+
"updatedBy" text,
|
|
195
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
196
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
197
|
+
);
|
|
198
|
+
--> statement-breakpoint
|
|
199
|
+
CREATE TABLE "docman_page_embed_links" (
|
|
200
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
201
|
+
"tenantId" text NOT NULL,
|
|
202
|
+
"pageVersionId" uuid NOT NULL,
|
|
203
|
+
"embedId" uuid NOT NULL,
|
|
204
|
+
"position" integer NOT NULL,
|
|
205
|
+
"caption" text,
|
|
206
|
+
"createdBy" text,
|
|
207
|
+
"updatedBy" text,
|
|
208
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
209
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
210
|
+
);
|
|
211
|
+
--> statement-breakpoint
|
|
212
|
+
CREATE UNIQUE INDEX "document_uid_unique" ON "docman_documents" USING btree ("tenantId","scopeId","documentUid");--> statement-breakpoint
|
|
213
|
+
CREATE INDEX "document_idx_tenant" ON "docman_documents" USING btree ("tenantId");--> statement-breakpoint
|
|
214
|
+
CREATE INDEX "document_idx_scope" ON "docman_documents" USING btree ("tenantId","scopeId");--> statement-breakpoint
|
|
215
|
+
CREATE INDEX "document_idx_status" ON "docman_documents" USING btree ("tenantId","status");--> statement-breakpoint
|
|
216
|
+
CREATE INDEX "document_idx_scope_slug" ON "docman_documents" USING btree ("tenantId","scopeId","slug");--> statement-breakpoint
|
|
217
|
+
CREATE INDEX "document_idx_scope_group_id" ON "docman_documents" USING btree ("tenantId","scopeId","groupId");--> statement-breakpoint
|
|
218
|
+
CREATE INDEX "document_idx_scope_group_uid" ON "docman_documents" USING btree ("tenantId","scopeId","groupUid");--> statement-breakpoint
|
|
219
|
+
CREATE UNIQUE INDEX "document_group_uid_unique" ON "docman_document_groups" USING btree ("tenantId","scopeId","groupUid");--> statement-breakpoint
|
|
220
|
+
CREATE INDEX "document_group_idx_tenant" ON "docman_document_groups" USING btree ("tenantId");--> statement-breakpoint
|
|
221
|
+
CREATE INDEX "document_group_idx_scope" ON "docman_document_groups" USING btree ("tenantId","scopeId");--> statement-breakpoint
|
|
222
|
+
CREATE INDEX "document_group_idx_parent" ON "docman_document_groups" USING btree ("tenantId","parentGroupId");--> statement-breakpoint
|
|
223
|
+
CREATE UNIQUE INDEX "document_version_unique" ON "docman_document_versions" USING btree ("tenantId","documentId","version");--> statement-breakpoint
|
|
224
|
+
CREATE INDEX "document_version_idx_doc" ON "docman_document_versions" USING btree ("tenantId","documentId");--> statement-breakpoint
|
|
225
|
+
CREATE INDEX "document_version_idx_status" ON "docman_document_versions" USING btree ("tenantId","status");--> statement-breakpoint
|
|
226
|
+
CREATE INDEX "document_version_idx_current" ON "docman_document_versions" USING btree ("tenantId","documentId","isCurrent");--> statement-breakpoint
|
|
227
|
+
CREATE UNIQUE INDEX "section_uid_unique" ON "docman_sections" USING btree ("tenantId","scopeId","sectionUid");--> statement-breakpoint
|
|
228
|
+
CREATE INDEX "section_idx_tenant" ON "docman_sections" USING btree ("tenantId");--> statement-breakpoint
|
|
229
|
+
CREATE INDEX "section_idx_scope" ON "docman_sections" USING btree ("tenantId","scopeId");--> statement-breakpoint
|
|
230
|
+
CREATE UNIQUE INDEX "page_uid_unique" ON "docman_pages" USING btree ("tenantId","scopeId","pageUid");--> statement-breakpoint
|
|
231
|
+
CREATE INDEX "page_idx_tenant" ON "docman_pages" USING btree ("tenantId");--> statement-breakpoint
|
|
232
|
+
CREATE INDEX "page_idx_scope" ON "docman_pages" USING btree ("tenantId","scopeId");--> statement-breakpoint
|
|
233
|
+
CREATE UNIQUE INDEX "page_version_unique" ON "docman_page_versions" USING btree ("tenantId","pageId","version");--> statement-breakpoint
|
|
234
|
+
CREATE INDEX "page_version_idx_page" ON "docman_page_versions" USING btree ("tenantId","pageId");--> statement-breakpoint
|
|
235
|
+
CREATE INDEX "page_version_idx_status" ON "docman_page_versions" USING btree ("tenantId","status");--> statement-breakpoint
|
|
236
|
+
CREATE UNIQUE INDEX "doc_section_pos_unique" ON "docman_document_section_links" USING btree ("tenantId","documentVersionId","parentLinkId","position");--> statement-breakpoint
|
|
237
|
+
CREATE INDEX "doc_section_idx_doc_version" ON "docman_document_section_links" USING btree ("tenantId","documentVersionId");--> statement-breakpoint
|
|
238
|
+
CREATE INDEX "doc_section_idx_section" ON "docman_document_section_links" USING btree ("tenantId","sectionId");--> statement-breakpoint
|
|
239
|
+
CREATE INDEX "doc_section_idx_page_version" ON "docman_document_section_links" USING btree ("tenantId","pageVersionId");--> statement-breakpoint
|
|
240
|
+
CREATE INDEX "doc_section_idx_parent" ON "docman_document_section_links" USING btree ("tenantId","parentLinkId");--> statement-breakpoint
|
|
241
|
+
CREATE UNIQUE INDEX "section_page_pos_unique" ON "docman_section_page_links" USING btree ("tenantId","sectionId","position");--> statement-breakpoint
|
|
242
|
+
CREATE INDEX "section_page_idx_section" ON "docman_section_page_links" USING btree ("tenantId","sectionId");--> statement-breakpoint
|
|
243
|
+
CREATE INDEX "section_page_idx_page_version" ON "docman_section_page_links" USING btree ("tenantId","pageVersionId");--> statement-breakpoint
|
|
244
|
+
CREATE UNIQUE INDEX "snippet_uid_unique" ON "docman_snippets" USING btree ("tenantId","scopeId","snippetUid");--> statement-breakpoint
|
|
245
|
+
CREATE INDEX "snippet_idx_tenant" ON "docman_snippets" USING btree ("tenantId");--> statement-breakpoint
|
|
246
|
+
CREATE INDEX "snippet_idx_scope" ON "docman_snippets" USING btree ("tenantId","scopeId");--> statement-breakpoint
|
|
247
|
+
CREATE INDEX "snippet_idx_scope_language" ON "docman_snippets" USING btree ("tenantId","scopeId","language");--> statement-breakpoint
|
|
248
|
+
CREATE UNIQUE INDEX "page_snippet_pos_unique" ON "docman_page_snippet_links" USING btree ("tenantId","pageVersionId","position");--> statement-breakpoint
|
|
249
|
+
CREATE INDEX "page_snippet_idx_page_version" ON "docman_page_snippet_links" USING btree ("tenantId","pageVersionId");--> statement-breakpoint
|
|
250
|
+
CREATE INDEX "page_snippet_idx_snippet" ON "docman_page_snippet_links" USING btree ("tenantId","snippetId");--> statement-breakpoint
|
|
251
|
+
CREATE UNIQUE INDEX "embed_uid_unique" ON "docman_embeds" USING btree ("tenantId","scopeId","embedUid");--> statement-breakpoint
|
|
252
|
+
CREATE INDEX "embed_idx_tenant" ON "docman_embeds" USING btree ("tenantId");--> statement-breakpoint
|
|
253
|
+
CREATE INDEX "embed_idx_scope" ON "docman_embeds" USING btree ("tenantId","scopeId");--> statement-breakpoint
|
|
254
|
+
CREATE INDEX "embed_idx_scope_type" ON "docman_embeds" USING btree ("tenantId","scopeId","type");--> statement-breakpoint
|
|
255
|
+
CREATE UNIQUE INDEX "page_embed_pos_unique" ON "docman_page_embed_links" USING btree ("tenantId","pageVersionId","position");--> statement-breakpoint
|
|
256
|
+
CREATE INDEX "page_embed_idx_page_version" ON "docman_page_embed_links" USING btree ("tenantId","pageVersionId");--> statement-breakpoint
|
|
257
|
+
CREATE INDEX "page_embed_idx_embed" ON "docman_page_embed_links" USING btree ("tenantId","embedId");
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
CREATE TABLE "docman_assets" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"tenantId" text NOT NULL,
|
|
4
|
+
"scopeId" uuid NOT NULL,
|
|
5
|
+
"assetUid" text NOT NULL,
|
|
6
|
+
"kind" text NOT NULL,
|
|
7
|
+
"title" text,
|
|
8
|
+
"slug" text,
|
|
9
|
+
"altText" text,
|
|
10
|
+
"currentVersionId" uuid,
|
|
11
|
+
"meta" jsonb,
|
|
12
|
+
"createdBy" text,
|
|
13
|
+
"updatedBy" text,
|
|
14
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
15
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
16
|
+
);
|
|
17
|
+
--> statement-breakpoint
|
|
18
|
+
CREATE TABLE "docman_asset_versions" (
|
|
19
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
20
|
+
"tenantId" text NOT NULL,
|
|
21
|
+
"assetId" uuid NOT NULL,
|
|
22
|
+
"version" integer NOT NULL,
|
|
23
|
+
"label" text,
|
|
24
|
+
"status" text NOT NULL,
|
|
25
|
+
"storageKey" text,
|
|
26
|
+
"sourcePath" text,
|
|
27
|
+
"sourceUrl" text,
|
|
28
|
+
"filename" text,
|
|
29
|
+
"mime" text NOT NULL,
|
|
30
|
+
"contentHash" text NOT NULL,
|
|
31
|
+
"byteSize" integer,
|
|
32
|
+
"width" integer,
|
|
33
|
+
"height" integer,
|
|
34
|
+
"variants" jsonb,
|
|
35
|
+
"meta" jsonb,
|
|
36
|
+
"createdBy" text,
|
|
37
|
+
"updatedBy" text,
|
|
38
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
39
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
40
|
+
);
|
|
41
|
+
--> statement-breakpoint
|
|
42
|
+
CREATE UNIQUE INDEX "asset_uid_unique" ON "docman_assets" USING btree ("tenantId","scopeId","assetUid");--> statement-breakpoint
|
|
43
|
+
CREATE INDEX "asset_idx_tenant" ON "docman_assets" USING btree ("tenantId");--> statement-breakpoint
|
|
44
|
+
CREATE INDEX "asset_idx_scope" ON "docman_assets" USING btree ("tenantId","scopeId");--> statement-breakpoint
|
|
45
|
+
CREATE INDEX "asset_idx_scope_kind" ON "docman_assets" USING btree ("tenantId","scopeId","kind");--> statement-breakpoint
|
|
46
|
+
CREATE INDEX "asset_idx_scope_current_version" ON "docman_assets" USING btree ("tenantId","scopeId","currentVersionId");--> statement-breakpoint
|
|
47
|
+
CREATE UNIQUE INDEX "asset_version_unique" ON "docman_asset_versions" USING btree ("tenantId","assetId","version");--> statement-breakpoint
|
|
48
|
+
CREATE INDEX "asset_version_idx_asset" ON "docman_asset_versions" USING btree ("tenantId","assetId");--> statement-breakpoint
|
|
49
|
+
CREATE INDEX "asset_version_idx_status" ON "docman_asset_versions" USING btree ("tenantId","status");--> statement-breakpoint
|
|
50
|
+
CREATE INDEX "asset_version_idx_hash" ON "docman_asset_versions" USING btree ("tenantId","contentHash");
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
CREATE TABLE "docman_document_index_entries" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
+
"tenantId" text NOT NULL,
|
|
4
|
+
"documentVersionId" uuid NOT NULL,
|
|
5
|
+
"documentId" uuid NOT NULL,
|
|
6
|
+
"locale" text DEFAULT '' NOT NULL,
|
|
7
|
+
"fallbackLocale" text DEFAULT '' NOT NULL,
|
|
8
|
+
"itemKind" text NOT NULL,
|
|
9
|
+
"sortOrder" integer NOT NULL,
|
|
10
|
+
"buildFingerprint" text NOT NULL,
|
|
11
|
+
"linkId" uuid,
|
|
12
|
+
"parentLinkId" uuid,
|
|
13
|
+
"anchor" text NOT NULL,
|
|
14
|
+
"parentAnchor" text,
|
|
15
|
+
"number" text,
|
|
16
|
+
"depth" integer NOT NULL,
|
|
17
|
+
"position" integer NOT NULL,
|
|
18
|
+
"title" text NOT NULL,
|
|
19
|
+
"breadcrumb" text NOT NULL,
|
|
20
|
+
"titleVisible" boolean DEFAULT true NOT NULL,
|
|
21
|
+
"pageBreakBefore" boolean DEFAULT false NOT NULL,
|
|
22
|
+
"pageBreakAfter" boolean DEFAULT false NOT NULL,
|
|
23
|
+
"sectionId" uuid,
|
|
24
|
+
"sectionUid" text,
|
|
25
|
+
"sectionSlug" text,
|
|
26
|
+
"pageId" uuid,
|
|
27
|
+
"pageUid" text,
|
|
28
|
+
"pageVersionId" uuid,
|
|
29
|
+
"format" text,
|
|
30
|
+
"pageNumberStart" integer,
|
|
31
|
+
"pageNumberEnd" integer,
|
|
32
|
+
"bodyText" text,
|
|
33
|
+
"searchText" text NOT NULL,
|
|
34
|
+
"createdBy" text,
|
|
35
|
+
"updatedBy" text,
|
|
36
|
+
"createdAt" timestamp with time zone DEFAULT now(),
|
|
37
|
+
"updatedAt" timestamp with time zone DEFAULT now()
|
|
38
|
+
);
|
|
39
|
+
--> statement-breakpoint
|
|
40
|
+
CREATE UNIQUE INDEX "doc_index_entry_sort_unique" ON "docman_document_index_entries" USING btree ("tenantId","documentVersionId","locale","fallbackLocale","sortOrder");--> statement-breakpoint
|
|
41
|
+
CREATE UNIQUE INDEX "doc_index_entry_anchor_unique" ON "docman_document_index_entries" USING btree ("tenantId","documentVersionId","locale","fallbackLocale","anchor");--> statement-breakpoint
|
|
42
|
+
CREATE INDEX "doc_index_entry_idx_doc_version" ON "docman_document_index_entries" USING btree ("tenantId","documentVersionId","locale","fallbackLocale");--> statement-breakpoint
|
|
43
|
+
CREATE INDEX "doc_index_entry_idx_link" ON "docman_document_index_entries" USING btree ("tenantId","linkId");--> statement-breakpoint
|
|
44
|
+
CREATE INDEX "doc_index_entry_idx_page_version" ON "docman_document_index_entries" USING btree ("tenantId","pageVersionId");--> statement-breakpoint
|
|
45
|
+
CREATE INDEX "doc_index_entry_idx_section" ON "docman_document_index_entries" USING btree ("tenantId","sectionId");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
ALTER TABLE "docman_document_index_entries" ADD COLUMN "summaryText" text;
|
|
2
|
+
--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "docman_document_index_entries" ADD COLUMN "sourceCharCount" integer DEFAULT 0 NOT NULL;
|
|
4
|
+
--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "docman_document_index_entries" ADD COLUMN "sourceWordCount" integer DEFAULT 0 NOT NULL;
|
|
6
|
+
--> statement-breakpoint
|
|
7
|
+
ALTER TABLE "docman_document_index_entries" ADD COLUMN "summaryCharCount" integer DEFAULT 0 NOT NULL;
|
|
8
|
+
--> statement-breakpoint
|
|
9
|
+
ALTER TABLE "docman_document_index_entries" ADD COLUMN "summaryWordCount" integer DEFAULT 0 NOT NULL;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
ALTER TABLE "docman_document_index_entries" ADD COLUMN "embeddingProvider" text;
|
|
2
|
+
--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "docman_document_index_entries" ADD COLUMN "embeddingModel" text;
|
|
4
|
+
--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "docman_document_index_entries" ADD COLUMN "embeddingHash" text;
|
|
6
|
+
--> statement-breakpoint
|
|
7
|
+
ALTER TABLE "docman_document_index_entries" ADD COLUMN "embeddingDimensions" integer;
|
|
8
|
+
--> statement-breakpoint
|
|
9
|
+
ALTER TABLE "docman_document_index_entries" ADD COLUMN "embeddingVector" text;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- Step 8 of docman set-current-version slice (consensus topic
|
|
2
|
+
-- aops-cli-doc-set-current-version-sugar-2026-05-18).
|
|
3
|
+
--
|
|
4
|
+
-- Enforces "at most one isCurrent=true row per (tenantId, documentId)" at the
|
|
5
|
+
-- database level. The new docman.document-version.set-current service op
|
|
6
|
+
-- already maintains this invariant inside its transaction, but a partial
|
|
7
|
+
-- unique index makes the invariant robust against future migrations, manual
|
|
8
|
+
-- SQL, or concurrent writers that might bypass the service path.
|
|
9
|
+
--
|
|
10
|
+
-- PostgreSQL supports partial unique indexes natively. SQLite supports the
|
|
11
|
+
-- same syntax, so the drizzle SQLite mirror can carry the same index.
|
|
12
|
+
|
|
13
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "document_version_unique_current"
|
|
14
|
+
ON "docman_document_versions" ("tenantId", "documentId")
|
|
15
|
+
WHERE "isCurrent" = true;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "7",
|
|
3
|
+
"dialect": "postgresql",
|
|
4
|
+
"entries": [
|
|
5
|
+
{
|
|
6
|
+
"idx": 0,
|
|
7
|
+
"version": "7",
|
|
8
|
+
"when": 1772831979646,
|
|
9
|
+
"tag": "0000_curvy_valeria_richards",
|
|
10
|
+
"breakpoints": true
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"idx": 1,
|
|
14
|
+
"version": "7",
|
|
15
|
+
"when": 1772833453900,
|
|
16
|
+
"tag": "0001_massive_risque",
|
|
17
|
+
"breakpoints": true
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"idx": 2,
|
|
21
|
+
"version": "7",
|
|
22
|
+
"when": 1773831701245,
|
|
23
|
+
"tag": "0002_simple_logan",
|
|
24
|
+
"breakpoints": true
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"idx": 3,
|
|
28
|
+
"version": "7",
|
|
29
|
+
"when": 1773837600000,
|
|
30
|
+
"tag": "0003_quick_index",
|
|
31
|
+
"breakpoints": true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"idx": 4,
|
|
35
|
+
"version": "7",
|
|
36
|
+
"when": 1773839700000,
|
|
37
|
+
"tag": "0004_known_summary",
|
|
38
|
+
"breakpoints": true
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"idx": 5,
|
|
42
|
+
"version": "7",
|
|
43
|
+
"when": 1773842400000,
|
|
44
|
+
"tag": "0005_vector_signal",
|
|
45
|
+
"breakpoints": true
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"idx": 6,
|
|
49
|
+
"version": "7",
|
|
50
|
+
"when": 1779113693327,
|
|
51
|
+
"tag": "0006_document_version_current_invariant",
|
|
52
|
+
"breakpoints": true
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aopslab/domain-pg-bootstrap-docman",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Owned PostgreSQL bootstrap/migration runner for Docman standalone/runtime flows.",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
"./package.json": "./package.json",
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"drizzle-out",
|
|
21
|
+
"!**/*.tsbuildinfo",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"NOTICE"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"pg": "8.20.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "25.3.0",
|
|
30
|
+
"@types/pg": "8.20.0",
|
|
31
|
+
"typescript": "5.9.3"
|
|
32
|
+
},
|
|
33
|
+
"license": "Apache-2.0",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/eeemzs/docman.git",
|
|
37
|
+
"directory": "docman-pg-bootstrap"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "node ./scripts/sync-migrations.mjs && tsc -b tsconfig.lib.json",
|
|
41
|
+
"typecheck": "tsc -p tsconfig.lib.json --noEmit"
|
|
42
|
+
}
|
|
43
|
+
}
|