xedoc-cli 0.1.2 → 0.1.4
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/build/server/index.js +1 -1
- package/package.json +1 -1
- package/server/sqlite-setup.mjs +114 -0
package/package.json
CHANGED
package/server/sqlite-setup.mjs
CHANGED
|
@@ -13,6 +13,7 @@ export async function setupSqliteDatabase() {
|
|
|
13
13
|
datasources: { db: { url: databaseUrl } },
|
|
14
14
|
})
|
|
15
15
|
try {
|
|
16
|
+
await migrateLegacyUserScopedTables(prisma)
|
|
16
17
|
await prisma.$executeRawUnsafe("PRAGMA foreign_keys = ON")
|
|
17
18
|
await prisma.$queryRawUnsafe("PRAGMA journal_mode = WAL")
|
|
18
19
|
await prisma.$queryRawUnsafe("PRAGMA busy_timeout = 30000")
|
|
@@ -30,6 +31,119 @@ export async function setupSqliteDatabase() {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
async function migrateLegacyUserScopedTables(prisma) {
|
|
35
|
+
await prisma.$executeRawUnsafe("PRAGMA foreign_keys = OFF")
|
|
36
|
+
try {
|
|
37
|
+
if (await tableHasColumn(prisma, "CodexAccount", "userId")) {
|
|
38
|
+
await rebuildCodexAccountTable(prisma)
|
|
39
|
+
}
|
|
40
|
+
if (await tableHasColumn(prisma, "Chat", "userId")) {
|
|
41
|
+
await rebuildChatTable(prisma)
|
|
42
|
+
}
|
|
43
|
+
} finally {
|
|
44
|
+
await prisma.$executeRawUnsafe("PRAGMA foreign_keys = ON")
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function tableHasColumn(prisma, tableName, columnName) {
|
|
49
|
+
try {
|
|
50
|
+
const columns = await prisma.$queryRawUnsafe(`PRAGMA table_info("${tableName}")`)
|
|
51
|
+
return columns.some((column) => column.name === columnName)
|
|
52
|
+
} catch {
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function rebuildCodexAccountTable(prisma) {
|
|
58
|
+
await prisma.$executeRawUnsafe('DROP TABLE IF EXISTS "CodexAccount_new"')
|
|
59
|
+
await prisma.$executeRawUnsafe(createCodexAccountTable("CodexAccount_new"))
|
|
60
|
+
await prisma.$executeRawUnsafe(`
|
|
61
|
+
INSERT INTO "CodexAccount_new" (
|
|
62
|
+
"id",
|
|
63
|
+
"displayName",
|
|
64
|
+
"status",
|
|
65
|
+
"command",
|
|
66
|
+
"args",
|
|
67
|
+
"environment",
|
|
68
|
+
"defaultModel",
|
|
69
|
+
"defaultPermissionMode",
|
|
70
|
+
"defaultReasoningEffort",
|
|
71
|
+
"defaultServiceTier",
|
|
72
|
+
"lastAuthUrl",
|
|
73
|
+
"lastError",
|
|
74
|
+
"createdAt",
|
|
75
|
+
"updatedAt"
|
|
76
|
+
)
|
|
77
|
+
SELECT
|
|
78
|
+
"id",
|
|
79
|
+
"displayName",
|
|
80
|
+
"status",
|
|
81
|
+
"command",
|
|
82
|
+
"args",
|
|
83
|
+
"environment",
|
|
84
|
+
${await selectColumnOrNull(prisma, "CodexAccount", "defaultModel")},
|
|
85
|
+
${await selectColumnOrNull(prisma, "CodexAccount", "defaultPermissionMode")},
|
|
86
|
+
${await selectColumnOrNull(prisma, "CodexAccount", "defaultReasoningEffort")},
|
|
87
|
+
${await selectColumnOrNull(prisma, "CodexAccount", "defaultServiceTier")},
|
|
88
|
+
"lastAuthUrl",
|
|
89
|
+
"lastError",
|
|
90
|
+
"createdAt",
|
|
91
|
+
"updatedAt"
|
|
92
|
+
FROM "CodexAccount"
|
|
93
|
+
`)
|
|
94
|
+
await prisma.$executeRawUnsafe('DROP TABLE "CodexAccount"')
|
|
95
|
+
await prisma.$executeRawUnsafe(
|
|
96
|
+
'ALTER TABLE "CodexAccount_new" RENAME TO "CodexAccount"',
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function rebuildChatTable(prisma) {
|
|
101
|
+
await prisma.$executeRawUnsafe('DROP TABLE IF EXISTS "Chat_new"')
|
|
102
|
+
await prisma.$executeRawUnsafe(createChatTable("Chat_new"))
|
|
103
|
+
await prisma.$executeRawUnsafe(`
|
|
104
|
+
INSERT INTO "Chat_new" (
|
|
105
|
+
"id",
|
|
106
|
+
"accountId",
|
|
107
|
+
"title",
|
|
108
|
+
"workingDirectory",
|
|
109
|
+
"model",
|
|
110
|
+
"reasoningEffort",
|
|
111
|
+
"serviceTier",
|
|
112
|
+
"collaborationMode",
|
|
113
|
+
"permissionMode",
|
|
114
|
+
"status",
|
|
115
|
+
"externalThreadId",
|
|
116
|
+
"lastActivityAt",
|
|
117
|
+
"createdAt",
|
|
118
|
+
"updatedAt"
|
|
119
|
+
)
|
|
120
|
+
SELECT
|
|
121
|
+
"id",
|
|
122
|
+
"accountId",
|
|
123
|
+
"title",
|
|
124
|
+
"workingDirectory",
|
|
125
|
+
"model",
|
|
126
|
+
"reasoningEffort",
|
|
127
|
+
"serviceTier",
|
|
128
|
+
"collaborationMode",
|
|
129
|
+
"permissionMode",
|
|
130
|
+
"status",
|
|
131
|
+
"externalThreadId",
|
|
132
|
+
"lastActivityAt",
|
|
133
|
+
"createdAt",
|
|
134
|
+
"updatedAt"
|
|
135
|
+
FROM "Chat"
|
|
136
|
+
`)
|
|
137
|
+
await prisma.$executeRawUnsafe('DROP TABLE "Chat"')
|
|
138
|
+
await prisma.$executeRawUnsafe('ALTER TABLE "Chat_new" RENAME TO "Chat"')
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function selectColumnOrNull(prisma, tableName, columnName) {
|
|
142
|
+
return (await tableHasColumn(prisma, tableName, columnName))
|
|
143
|
+
? `"${columnName}"`
|
|
144
|
+
: "NULL"
|
|
145
|
+
}
|
|
146
|
+
|
|
33
147
|
function isDuplicateColumnError(error) {
|
|
34
148
|
const message = error instanceof Error ? error.message : String(error)
|
|
35
149
|
return message.toLowerCase().includes("duplicate column name")
|