Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: introduce sqlite as a plugabble metadata store #3401

Merged
merged 63 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
a5dfb6d
add metadata store
kevinslin Jul 31, 2022
09e066e
add prisma
kevinslin Jul 31, 2022
d3c7d2a
add sqlite store to engine
kevinslin Jul 31, 2022
d7cc94f
minor init fixes
kevinslin Jul 31, 2022
8a13e97
prisma stuff
kevinslin Jul 31, 2022
18200eb
stable snapshot
kevinslin Aug 6, 2022
e76ab21
sqlite quote fixes
kevinslin Aug 6, 2022
2c696e8
stable
kevinslin Aug 6, 2022
b2758c6
normalize query
kevinslin Aug 6, 2022
dd51d01
create all tables if no tables exist
kevinslin Aug 7, 2022
05ef239
init per vault
kevinslin Aug 7, 2022
9a33cbc
add some error logic
kevinslin Aug 7, 2022
d8d946f
add diagnostics
kevinslin Aug 9, 2022
2bd7b35
snap
kevinslin Aug 10, 2022
7d532b2
throw error and write to disk
kevinslin Aug 10, 2022
e2f7355
export sqlite
kevinslin Aug 15, 2022
c02d56d
add comments
kevinslin Aug 15, 2022
7ba4e19
add script to build prisma client
kevinslin Aug 15, 2022
0c14e44
add tests
kevinslin Aug 16, 2022
e939454
updates
kevinslin Aug 19, 2022
e38a0f8
add tests
kevinslin Aug 19, 2022
81bc891
remove debugger
kevinslin Aug 19, 2022
989f4bb
update metadata when notes change
kevinslin Aug 19, 2022
354ca05
update cache
kevinslin Aug 19, 2022
0d4460b
update makefile
kevinslin Aug 20, 2022
69df351
update build
kevinslin Aug 20, 2022
9b65474
update make
kevinslin Aug 20, 2022
f955ee8
update make
kevinslin Aug 20, 2022
cdad725
add comments
kevinslin Aug 20, 2022
a1e91e9
test
kevinslin Aug 20, 2022
34a8cd9
chore: publish patch
kevinslin Aug 20, 2022
f089723
add logs
kevinslin Aug 20, 2022
cef8476
chore: publish patch
kevinslin Aug 20, 2022
51c9364
update
kevinslin Aug 20, 2022
5f69bc2
modify
kevinslin Aug 20, 2022
3ef8b10
revert
kevinslin Aug 20, 2022
9103644
update
kevinslin Aug 21, 2022
a3a9970
remove export
kevinslin Aug 21, 2022
b57f7eb
Revert "chore: publish patch"
kevinslin Aug 21, 2022
028d3bd
Revert "chore: publish patch"
kevinslin Aug 21, 2022
7acef00
adjust location of prisma-client
kevinslin Aug 21, 2022
1b5bb69
add comments
kevinslin Aug 21, 2022
943b664
chore: publish patch
kevinslin Aug 21, 2022
5a5aed3
fix formatting
kevinslin Aug 21, 2022
c2b2a2e
engine server modification in build
kevinslin Aug 21, 2022
2265818
add copy script
kevinslin Aug 21, 2022
6369574
update build script
kevinslin Aug 21, 2022
9b4b15d
Revert "chore: publish patch"
kevinslin Aug 21, 2022
b956d96
update dev cli
kevinslin Aug 21, 2022
bbb418c
update cli
kevinslin Aug 21, 2022
1389799
update build
kevinslin Aug 21, 2022
b556983
update
kevinslin Aug 21, 2022
05d9dc6
remove dist changes
kevinslin Aug 22, 2022
e2bb577
remove modify engine
kevinslin Aug 22, 2022
d1d7e0b
chore: publish patch
kevinslin Aug 22, 2022
22e213f
update tests
kevinslin Aug 22, 2022
2816889
add additional targets
kevinslin Aug 22, 2022
bf327e6
Revert "chore: publish patch"
kevinslin Aug 22, 2022
fc7cf37
dont skip windows test
kevinslin Aug 22, 2022
7713add
fix compiler issue
kevinslin Aug 22, 2022
b2b7554
skip windows tests
kevinslin Aug 22, 2022
f59c08b
add windows support
kevinslin Aug 22, 2022
de12e76
skip windows
kevinslin Aug 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
with:
path: |
packages/*/lib/*
key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}-21
key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}-22
restore-keys: |
${{ runner.os }}-yarn-9

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ packages/nextjs-template/public
.npmrc
.env.production
packages/dendron-viz/lib
generated-prisma-client
packages/engine-server/prisma/dev.db
dev.db-journal
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,20 @@ cleanBuild:
echo "Clean building..."
make clean
make install

db-gen:
cd packages/engine-server && yarn prisma generate
cd packages/engine-server && rm -rf lib/generated-prisma-client
cd packages/engine-server && cp -R src/generated-prisma-client lib/generated-prisma-client

start-local-registry:
yarn config set registry http://localhost:4873
npm set registry http://localhost:4873/
npx verdaccio -c ./bootstrap/data/verdaccio/config.yaml

publish-local:
lerna publish from-package --ignore-scripts

build-plugin:
dendron dev prep_plugin && rm package.json
dendron dev package_plugin
12 changes: 6 additions & 6 deletions bootstrap/scripts/buildAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ const $ = (cmd) => {

console.log("building all...");
$(`npx lerna run build --scope @dendronhq/common-all`);
$(`npx lerna run build --scope @dendronhq/common-server `);
$(`npx lerna run build --scope @dendronhq/dendron-viz `);
$(`npx lerna run build --scope @dendronhq/engine-server `);
$(`npx lerna run build --scope @dendronhq/pods-core `);
$(`npx lerna run build --scope @dendronhq/common-server`);
$(`npx lerna run build --scope @dendronhq/dendron-viz`);
$(`npx lerna run build --scope @dendronhq/engine-server`);
$(`npx lerna run build --scope @dendronhq/pods-core`);
$(
`npx lerna run build --parallel --scope "@dendronhq/{common-test-utils,api-server,common-assets}"`
`npx lerna run build --parallel --scope "@dendronhq/{common-test-utils,api-server,common-assets}"`
);
$(
`npx lerna run build --parallel --scope "@dendronhq/{common-frontend,dendron-cli}"`
`npx lerna run build --parallel --scope "@dendronhq/{common-frontend,dendron-cli}"`
);
$(`npx lerna run build --scope "@dendronhq/engine-test-utils"`);
$(`npx lerna run build --scope "@dendronhq/dendron-plugin-views"`);
Expand Down
7 changes: 7 additions & 0 deletions packages/common-all/data/dendron-yml.validator.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,13 @@
},
"apiEndpoint": {
"type": "string"
},
"metadataStore": {
"type": "string",
"enum": [
"sqlite",
"json"
]
}
},
"required": [
Expand Down
4 changes: 4 additions & 0 deletions packages/common-all/src/constants/configs/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,8 @@ export const WORKSPACE: DendronConfigEntryCollection<DendronWorkspaceConfig> = {
label: "Enable smart references",
desc: "When enabled, note references that include a header will transclude said header and all sub headers",
},
metadataStore: {
label: "Storage engine for metadata",
desc: "values: sqlite|json",
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type DendronWorkspaceConfig = {
//
feedback?: boolean;
apiEndpoint?: string;
metadataStore?: "sqlite" | "json";
};

export type DendronWorkspace = {
Expand Down
7 changes: 1 addition & 6 deletions packages/dendron-cli/src/commands/devCLICommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ export class DevCLICommand extends CLICommand<CommandOpts, CommandOutput> {
await this.syncAssets(opts);

this.print("prep repo...");
await BuildUtils.prepPluginPkg();
jonathanyeung marked this conversation as resolved.
Show resolved Hide resolved
await BuildUtils.prepPluginPkg(opts.extensionTarget);

if (!shouldPublishLocal) {
this.print(
Expand All @@ -468,11 +468,6 @@ export class DevCLICommand extends CLICommand<CommandOpts, CommandOutput> {
this.print("compiling plugin...");
await BuildUtils.compilePlugin(opts);

if (opts.extensionTarget === ExtensionTarget.NIGHTLY) {
this.print("modifying plugin manifest for nightly target...");
await BuildUtils.prepPluginPkg(ExtensionTarget.NIGHTLY);
}

this.print("package deps...");
await BuildUtils.packagePluginDependencies(opts);

Expand Down
12 changes: 12 additions & 0 deletions packages/dendron-cli/src/utils/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ export class BuildUtils {
"@dendronhq/engine-test-utils",
],
});

await fs.copy(
path.join(
this.getPluginRootPath(),
"..",
"engine-server",
"src",
"drivers",
"generated-prisma-client"
),
path.join(this.getPluginRootPath(), "dist", "generated-prisma-client")
);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions packages/engine-server/copyPrismaClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fs = require("fs-extra");
const path = require("path");

function main() {
const libPath = path.join(__dirname, "lib", "drivers", "generated-prisma-client");
const srcPath = path.join("src", "drivers", "generated-prisma-client");
fs.ensureDirSync(libPath);
fs.copy(srcPath, libPath, { overwrite: true });
console.log("done");
}

main();
11 changes: 7 additions & 4 deletions packages/engine-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"clean": "rimraf lib && rimraf coverage",
"clean": "rimraf lib && rimraf coverage && rimraf src/drivers/generated-prisma-client",
"format": "echo nop",
"lint": "echo stub",
"buildPrismaClient": "yarn prisma generate && node copyPrismaClient.js",
"prepublishOnly": "yarn build",
"prebuild": "yarn clean && yarn format && yarn lint && echo Using TypeScript && tsc --version",
"build": "yarn compile",
"buildCI": "yarn compile",
"build": "yarn buildPrismaClient && yarn compile",
"buildCI": "yarn compile && yarn buildPrismaClient",
"compile": "tsc -p tsconfig.build.json ",
"watch": "yarn compile --watch"
},
Expand All @@ -39,6 +40,7 @@
"@dendronhq/remark-mermaid": "^0.3.0",
"@jcoreio/async-throttle": "^1.4.3",
"@mapbox/rehype-prism": "^0.5.0",
"@prisma/client": "^4.1.1",
"axios": "^0.21.1",
"chokidar": "^3.5.2",
"cross-path-sort": "^1.0.0",
Expand All @@ -53,6 +55,7 @@
"mdast-builder": "^1.1.1",
"mdast-util-compact": "^2.0.1",
"mdast-util-inject": "^1.1.0",
"prisma": "^4.1.1",
"qs": "^6.10.1",
"rehype-autolink-headings": "^5.0.1",
"rehype-katex": "5",
Expand All @@ -78,7 +81,7 @@
"unified-engine": "^8.0.0",
"unist-util-select": "^3.0.1",
"unist-util-visit": "^2.0.3",
"vscode-uri": "^2.1.2"
"vscode-uri": "3.0.3"
},
"devDependencies": {
"@types/execa": "^2.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- CreateTable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this path naming intentional? packages/engine-server/prisma/migrations/20220819014343_add_davult/migration.sql

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autogenerated by prisma

CREATE TABLE "notes" (
"fname" TEXT,
"id" TEXT NOT NULL PRIMARY KEY,
"title" TEXT,
"vault" TEXT,
"updated" INTEGER,
"created" INTEGER,
"stub" BOOLEAN,
"anchors" json,
"desc" TEXT,
"links" json
);

-- CreateTable
CREATE TABLE "DVault" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT,
"relativePath" TEXT NOT NULL,
"schemaVersion" INTEGER NOT NULL
);

-- CreateIndex
CREATE INDEX "idx_notes_id" ON "notes"("id");
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Warnings:

- You are about to drop the `notes` table. If the table is not empty, all the data it contains will be lost.
- The primary key for the `DVault` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `id` on the `DVault` table. All the data in the column will be lost.
- You are about to drop the column `relativePath` on the `DVault` table. All the data in the column will be lost.
- You are about to drop the column `schemaVersion` on the `DVault` table. All the data in the column will be lost.
- Added the required column `fsPath` to the `DVault` table without a default value. This is not possible if the table is not empty.
- Added the required column `wsRoot` to the `DVault` table without a default value. This is not possible if the table is not empty.

*/
-- DropIndex
DROP INDEX "idx_notes_id";

-- DropTable
PRAGMA foreign_keys=off;
DROP TABLE "notes";
PRAGMA foreign_keys=on;

-- CreateTable
CREATE TABLE "Note" (
"fname" TEXT,
"id" TEXT NOT NULL PRIMARY KEY,
"title" TEXT,
"updated" INTEGER,
"created" INTEGER,
"stub" BOOLEAN,
"dVaultWsRoot" TEXT NOT NULL,
"dVaultFsPath" TEXT NOT NULL,
CONSTRAINT "Note_dVaultWsRoot_dVaultFsPath_fkey" FOREIGN KEY ("dVaultWsRoot", "dVaultFsPath") REFERENCES "DVault" ("wsRoot", "fsPath") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "Workspace" (
"wsRoot" TEXT NOT NULL PRIMARY KEY,
"prismaSchemaVersion" INTEGER NOT NULL
);

-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_DVault" (
"name" TEXT,
"fsPath" TEXT NOT NULL,
"wsRoot" TEXT NOT NULL,
CONSTRAINT "DVault_wsRoot_fkey" FOREIGN KEY ("wsRoot") REFERENCES "Workspace" ("wsRoot") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_DVault" ("name") SELECT "name" FROM "DVault";
DROP TABLE "DVault";
ALTER TABLE "new_DVault" RENAME TO "DVault";
CREATE UNIQUE INDEX "DVault_wsRoot_fsPath_key" ON "DVault"("wsRoot", "fsPath");
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;

-- CreateIndex
CREATE INDEX "idx_notes_id" ON "Note"("id");

-- CreateIndex
CREATE UNIQUE INDEX "Workspace_wsRoot_key" ON "Workspace"("wsRoot");
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Warnings:

- You are about to drop the column `dVaultFsPath` on the `Note` table. All the data in the column will be lost.
- You are about to drop the column `dVaultWsRoot` on the `Note` table. All the data in the column will be lost.
- Added the required column `id` to the `DVault` table without a default value. This is not possible if the table is not empty.
- Added the required column `dVaultId` to the `Note` table without a default value. This is not possible if the table is not empty.

*/
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_DVault" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT,
"fsPath" TEXT NOT NULL,
"wsRoot" TEXT NOT NULL,
CONSTRAINT "DVault_wsRoot_fkey" FOREIGN KEY ("wsRoot") REFERENCES "Workspace" ("wsRoot") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_DVault" ("fsPath", "name", "wsRoot") SELECT "fsPath", "name", "wsRoot" FROM "DVault";
DROP TABLE "DVault";
ALTER TABLE "new_DVault" RENAME TO "DVault";
CREATE UNIQUE INDEX "DVault_name_key" ON "DVault"("name");
CREATE UNIQUE INDEX "DVault_wsRoot_fsPath_key" ON "DVault"("wsRoot", "fsPath");
CREATE TABLE "new_Note" (
"id" TEXT NOT NULL PRIMARY KEY,
"fname" TEXT,
"title" TEXT,
"updated" INTEGER,
"created" INTEGER,
"stub" BOOLEAN,
"dVaultId" INTEGER NOT NULL,
CONSTRAINT "Note_dVaultId_fkey" FOREIGN KEY ("dVaultId") REFERENCES "DVault" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Note" ("created", "fname", "id", "stub", "title", "updated") SELECT "created", "fname", "id", "stub", "title", "updated" FROM "Note";
DROP TABLE "Note";
ALTER TABLE "new_Note" RENAME TO "Note";
CREATE INDEX "idx_notes_id" ON "Note"("id");
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;
3 changes: 3 additions & 0 deletions packages/engine-server/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"
43 changes: 43 additions & 0 deletions packages/engine-server/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "darwin-arm64", "darwin", "windows", "debian-openssl-1.1.x"]
output = "./../src/drivers/generated-prisma-client"
}

datasource db {
provider = "sqlite"
url = "file:./dev.db"
}

model Note {
id String @id
fname String?
title String?
vault DVault @relation(fields: [dVaultId], references: [id])
updated Int?
created Int?
stub Boolean?
// anchors Unsupported("json")?
// desc String?
// links Unsupported("json")?
dVaultId Int

@@index([id], map: "idx_notes_id")
}

model DVault {
id Int @id @default(autoincrement())
name String? @unique
fsPath String
wsRoot String
workspace Workspace @relation(fields: [wsRoot], references: [wsRoot], onDelete: Cascade)
Note Note[]

@@unique([wsRoot, fsPath])
}

model Workspace {
wsRoot String @id @unique
prismaSchemaVersion Int
vaults DVault[]
}