Skip to content

Commit 15bc779

Browse files
committed
various cleanup
- improve db handling - fix some build stuff - import includeWikis as separate bags and other load-wiki-folder improvements
1 parent feac38b commit 15bc779

37 files changed

Lines changed: 939 additions & 674 deletions

package-lock.json

Lines changed: 35 additions & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,21 @@
5050
"env": "env",
5151
"test": "node scripts/scripts.mjs test",
5252
"prisma:gen": "cd tools && npm run prisma:gen",
53-
"prisma:mig": "cd tools && npm run prisma:mig",
54-
"postinstall": "(cd tools && npm i)"
53+
"prisma:mig": "cd tools && npm run prisma:mig"
5554
},
5655
"dependencies": {
57-
"@material-symbols/svg-400": "^0.45.3",
58-
"@prisma/client": "^7.2.0",
56+
"@prisma/adapter-better-sqlite3": "7.8.0",
57+
"@prisma/client": "7.8.0",
5958
"@serenity-kit/opaque": "^0.8.4",
60-
"@types/pg": "^8.20.0",
6159
"source-map-support": "^0.5.21",
6260
"tiddlywiki": "^5.3.2"
6361
},
6462
"devDependencies": {
65-
"@prisma/adapter-better-sqlite3": "7.2.0",
66-
"@types/dropzone": "^5.7.9",
6763
"@types/node": "^24.6.0",
68-
"@types/source-map-support": "^0.5.10",
69-
"dropzone": "^6.0.0-beta.2"
64+
"@types/pg": "^8.20.0",
65+
"@types/source-map-support": "^0.5.10"
7066
},
7167
"peerDependencies": {
7268
"tiddlywiki": "^5.3.2"
7369
}
74-
}
70+
}

packages/admin-vanilla/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dependencies": {
88
"@fontsource/roboto": "^5.2.6",
99
"@material/web": "^2.4.0",
10+
"@material-symbols/svg-400": "^0.45.3",
1011
"@mdui/icons": "^1.0.3",
1112
"@types/luxon": "^3.6.2",
1213
"esbuild-plugin-copy": "^2.1.1",
@@ -17,4 +18,4 @@
1718
"uuid": "^13.0.0",
1819
"rxjs": "7"
1920
}
20-
}
21+
}

packages/admin-vanilla/src/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
import { adminStorage, createDraft, getEmptyItems, jsonReviver } from "./definition/store";
3030
import { definitely, is } from "./definition/utils";
3131
import { logout } from "./passwords";
32-
import { fieldTypeRenderSidebars, formatFieldValue, renderFieldEditor, renderFieldSidebar } from "./definition/renders";
32+
import { fieldTypeRenderSidebars, formatFieldValue, renderFieldEditor, renderFieldSidebar, textWithSlashes } from "./definition/renders";
3333

3434

3535
export type AdminRecord = { id: IdString; };
@@ -1033,7 +1033,7 @@ function renderListCellValue(columnKey: string, value: string | undefined) {
10331033
);
10341034
}
10351035

1036-
return formattedValue;
1036+
return textWithSlashes(formattedValue);
10371037
}
10381038

10391039
function getListColumnLink(tabId: TabId, columnKey: string, item: AdminRecord): string | null {

packages/admin-vanilla/src/definition/renders.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,15 @@ function renderLinesList(value: readonly string[], key: string, itemsByTab?: Adm
185185
null : null;
186186
const lines = value.map(line => ({ line, missing: missingCheck && !missingCheck.has(line), }));
187187
return <ul class="value-list">{lines.map(({ line, missing }) => <li>
188-
{line.split("/").map((e, i, a) => <>{e}{(i !== a.length - 1) ? "/" : ""}<wbr /></>)}
188+
{textWithSlashes(line)}
189189
{missing ? <span class="missing-marker" aria-label="Missing dependency" title="Missing dependency"><MaterialSymbol icon={warningIcon} /></span> : null}
190190
</li>)}</ul>;
191191

192192
}
193+
export function textWithSlashes(line: string): JSX.Node[] {
194+
return line.split("/").map((e, i, a) => <>{e}{(i !== a.length - 1) ? "/" : ""}<wbr /></>);
195+
}
196+
193197
function renderCalloutField(ctx: ReadonlyFieldContext) {
194198
definitely<string>(ctx.value);
195199
return <div class="field-callout"><p>{formatFieldValue(ctx.value)}</p></div>;

packages/mws/src/db/sqlite-adapter.ts

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,13 @@ export class SqliteAdapter {
1717

1818
adapter!: SqlMigrationAwareDriverAdapterFactory;
1919
async init() {
20+
console.log("CWD: " + process.cwd());
21+
console.log("DB: " + this.databasePath);
22+
2023
const libsql = await this.adapter.connect();
2124

2225
// this is used to test the upgrade path
23-
if (process.env.RUN_FIRST_MWS_DB_SETUP_FOR_TESTING_0_0) {
24-
throw new Error("this is disabled");
25-
await libsql.executeScript(await readFile(dist_resolve(
26-
"../prisma-20250406/migrations/" + INIT_0_0 + "/migration.sql"
27-
), "utf8"));
28-
} else if (process.env.RUN_FIRST_MWS_DB_SETUP_FOR_TESTING_0_1) {
29-
await libsql.executeScript(await readFile(dist_resolve(
30-
"../prisma/migrations/" + INIT_0_1 + "/migration.sql"
31-
), "utf8"));
32-
} else if (process.env.RUN_FIRST_MWS_DB_SETUP_FOR_TESTING_0_2) {
26+
if (process.env.RUN_FIRST_MWS_DB_SETUP_FOR_TESTING_0_2) {
3327
await libsql.executeScript(await readFile(dist_resolve(
3428
"../prisma/migrations/" + INIT_0_2 + "/migration.sql"
3529
), "utf8"));
@@ -62,8 +56,12 @@ export class SqliteAdapter {
6256
argTypes: [],
6357
}).then(e => e.rows.map(e => e[0] as string))
6458
);
59+
const oldVersion =
60+
applied_migrations.has(INIT_0_0) ? "0.0" :
61+
applied_migrations.has(INIT_0_1) ? "0.1" :
62+
undefined;
6563

66-
if (applied_migrations.has(INIT_0_0)) {
64+
if (oldVersion) {
6765
console.log([
6866
"=======================================================================================",
6967
"The database you are trying to open is from a previous version of MWS.",
@@ -72,20 +70,19 @@ export class SqliteAdapter {
7270
"wikis you want to keep by opening them and downloading them as single-file",
7371
"wikis by clicking on the cloud status icon and then 'save snapshot for offline use'.",
7472
"",
73+
"CWD: " + process.cwd(),
74+
"DB: " + this.databasePath,
75+
"",
7576
"To return to a usable version of this wiki, you may run ",
7677
"",
77-
"npm install @tiddlywiki/mws@0.0",
78+
"npm install @tiddlywiki/mws@" + oldVersion,
79+
"",
80+
"To prevent data loss the program will now exit.",
7881
"=======================================================================================",
7982
].join("\n"))
80-
await this.checkMigrationsTable(libsql, hasExisting && !hasMigrationsTable, applied_migrations, "prisma-20250406", INIT_0_0);
81-
console.log("Your database is updated to the final version for 0.0.x");
82-
console.log("This database is for a previous version of MWS. We will now exit to prevent data loss.");
83-
console.log("=======================================================================================");
8483
process.exit(1);
85-
// } else if (!applied_migrations.size || applied_migrations.has(INIT_0_1)) {
86-
// await this.checkMigrationsTable(libsql, hasExisting && !hasMigrationsTable, applied_migrations, "prisma", INIT_0_1);
8784
} else if (!applied_migrations.size || applied_migrations.has(INIT_0_2)) {
88-
await this.checkMigrationsTable(libsql, hasExisting && !hasMigrationsTable, applied_migrations, "prisma", INIT_0_2);
85+
await this.checkMigrationsTable(libsql, applied_migrations, "prisma/migrations");
8986
} else if (this.isDevMode) {
9087
console.log([
9188
"===============================================================",
@@ -137,13 +134,13 @@ export class SqliteAdapter {
137134
// prisma/migrations/20250508171144_init/migration.sql
138135
async checkMigrationsTable(
139136
libsql: SqlDriverAdapter,
140-
migrateExisting: boolean,
141137
applied_migrations: Set<string>,
142-
prismaFolder: string,
143-
initMigration: string
138+
prismaMigrationsFolder: string
144139
) {
145140

146-
const migrations = await readdir(dist_resolve("../" + prismaFolder + "/migrations"));
141+
const migrations = await readdir(dist_resolve("../" + prismaMigrationsFolder));
142+
// the folder names are the iso digit string
143+
// NOTE: Of all the insanities, numbers are sorted as strings!
147144
migrations.sort();
148145

149146
const new_migrations = migrations.filter(m => !applied_migrations.has(m) && m !== "migration_lock.toml");
@@ -156,17 +153,13 @@ export class SqliteAdapter {
156153
console.log("New migrations found", new_migrations);
157154

158155
for (const migration of new_migrations) {
159-
const migration_path = dist_resolve(`../${prismaFolder}/migrations/${migration}/migration.sql`);
156+
const migration_path = dist_resolve(`../${prismaMigrationsFolder}/${migration}/migration.sql`);
160157
if (!existsSync(migration_path)) continue;
161158

162159
const fileContent = await readFile(migration_path, 'utf-8');
163-
// this is the hard-coded name of the first migration.
164-
if (migrateExisting && migration === initMigration) {
165-
console.log("Existing migration", migration, "is already applied");
166-
} else {
167-
console.log("Applying migration", migration);
168-
await libsql.executeScript(fileContent);
169-
}
160+
161+
console.log("Applying migration", migration);
162+
await libsql.executeScript(fileContent);
170163

171164
await libsql.executeRaw(InsertStatement("_prisma_migrations", [
172165
{

packages/mws/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export {
5252
export * from "./new-commands";
5353
export * from "./new-managers";
5454

55+
export * from "@tiddlywiki/mws-prisma";
5556

5657
export default async function runMWS(oldOptions?: any) {
5758
// detect version 0.0 and exit

packages/mws/src/new-commands/init-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ export class InitStoreCommand extends BaseCommand {
7979

8080
const runner = async (path: string, bagName: string, bagDesc: string, recName: string, recDesc: string) => {
8181
const command = new LoadWikiFolderCommand([path!], {
82-
"bag-name": [bagName],
82+
"bag-relative-root": [dist_resolve("..")],
8383
"bag-description": [bagDesc],
8484
"recipe-name": [recName],
8585
"recipe-description": [recDesc],
86-
overwrite: false,
86+
"overwrite": false,
8787
"owner-roles": ["ADMIN"]
8888
});
8989
command.$tw = this.$tw;

0 commit comments

Comments
 (0)