Skip to content

Commit 58ba7a3

Browse files
committed
dev-demo: add update_adminforth_plugins and add 'sessions/turns" resource
1 parent b59df81 commit 58ba7a3

5 files changed

Lines changed: 173 additions & 1 deletion

File tree

dev-demo/Taskfile.yaml

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,58 @@ tasks:
104104
fi
105105
' _ {}
106106
107+
update_adminforth_repos:
108+
internal: true
109+
cmds:
110+
- |
111+
set -euo pipefail
112+
cd "{{.DIR}}"
113+
114+
repos=({{range .REPOS}}{{.}} {{end}})
115+
116+
printf '%s\n' "${repos[@]}" | xargs -n1 -P"{{.PNPM_JOBS}}" -I{} bash -c '
117+
set -euo pipefail
118+
name="$1"
119+
120+
if [ ! -d "${name}" ]; then
121+
echo "Directory ${name} does not exist, skipping"
122+
exit 0
123+
fi
124+
125+
echo "Updating adminforth in ${name}"
126+
cd "${name}"
127+
128+
if ! git diff --cached --quiet; then
129+
echo "Repository ${name} has staged changes, skipping"
130+
exit 0
131+
fi
132+
133+
if ! git diff --quiet -- package.json || ! git diff --cached --quiet -- package.json; then
134+
echo "Repository ${name} has pending dependency file changes, skipping"
135+
exit 0
136+
fi
137+
138+
if [ -f pnpm-lock.yaml ] && { ! git diff --quiet -- pnpm-lock.yaml || ! git diff --cached --quiet -- pnpm-lock.yaml; }; then
139+
echo "Repository ${name} has pending dependency file changes, skipping"
140+
exit 0
141+
fi
142+
143+
pnpm i adminforth@latest
144+
145+
git add package.json
146+
if [ -e pnpm-lock.yaml ]; then
147+
git add pnpm-lock.yaml
148+
fi
149+
150+
if git diff --cached --quiet; then
151+
echo "No adminforth update needed in ${name}"
152+
exit 0
153+
fi
154+
155+
git commit -m "fix: update adminforth verion"
156+
git push
157+
' _ {}
158+
107159
pull_plugins:
108160
desc: Pull plugin repositories
109161
cmds:
@@ -138,4 +190,13 @@ tasks:
138190
vars:
139191
DIR: "{{.ADAPTERS_DIR}}"
140192
REPOS:
141-
ref: .ADAPTERS
193+
ref: .ADAPTERS
194+
195+
update_adminforth_plugins:
196+
desc: Update adminforth to latest in plugin repositories, commit, and push
197+
cmds:
198+
- task: update_adminforth_repos
199+
vars:
200+
DIR: "{{.PLUGINS_DIR}}"
201+
REPOS:
202+
ref: .PLUGINS
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- CreateTable
2+
CREATE TABLE "sessions" (
3+
"id" TEXT NOT NULL PRIMARY KEY,
4+
"title" TEXT NOT NULL,
5+
"turns" INTEGER,
6+
"asker_id" TEXT NOT NULL,
7+
"created_at" DATETIME NOT NULL
8+
);
9+
10+
-- CreateTable
11+
CREATE TABLE "turns" (
12+
"id" TEXT NOT NULL PRIMARY KEY,
13+
"session_id" TEXT NOT NULL,
14+
"created_at" DATETIME NOT NULL,
15+
"prompt" TEXT,
16+
"response" TEXT
17+
);

dev-demo/migrations/prisma/sqlite/schema.prisma

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,20 @@ model adminuserCars {
109109
id String @id
110110
adminuserId String
111111
carId String
112+
}
113+
114+
model sessions {
115+
id String @id
116+
title String
117+
turns Int?
118+
asker_id String
119+
created_at DateTime
120+
}
121+
122+
model turns {
123+
id String @id
124+
session_id String
125+
created_at DateTime
126+
prompt String?
127+
response String?
112128
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import AdminForth, { AdminForthDataTypes } from 'adminforth';
2+
import type { AdminForthResourceInput, AdminUser } from 'adminforth';
3+
import { randomUUID } from 'crypto';
4+
5+
export default {
6+
dataSource: 'sqlite',
7+
table: 'sessions',
8+
resourceId: 'sessions',
9+
label: 'Sessions',
10+
columns: [
11+
{
12+
name: 'id',
13+
primaryKey: true,
14+
type: AdminForthDataTypes.STRING,
15+
fillOnCreate: ({ initialRecord, adminUser }) => randomUUID(),
16+
showIn: {
17+
edit: false,
18+
create: false,
19+
},
20+
},
21+
{
22+
name: 'title',
23+
type: AdminForthDataTypes.STRING,
24+
},
25+
{
26+
name: 'turns',
27+
type: AdminForthDataTypes.INTEGER,
28+
},
29+
{
30+
name: 'asker_id',
31+
type: AdminForthDataTypes.STRING,
32+
},
33+
{
34+
name: 'created_at',
35+
type: AdminForthDataTypes.DATE,
36+
fillOnCreate: () => new Date(),
37+
}
38+
],
39+
} as AdminForthResourceInput;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import AdminForth, { AdminForthDataTypes } from 'adminforth';
2+
import type { AdminForthResourceInput, AdminUser } from 'adminforth';
3+
import { randomUUID } from 'crypto';
4+
5+
export default {
6+
dataSource: 'sqlite',
7+
table: 'turns',
8+
resourceId: 'turns',
9+
label: 'Turns',
10+
columns: [
11+
{
12+
name: 'id',
13+
primaryKey: true,
14+
type: AdminForthDataTypes.STRING,
15+
fillOnCreate: ({ initialRecord, adminUser }) => randomUUID(),
16+
showIn: {
17+
edit: false,
18+
create: false,
19+
},
20+
},
21+
{
22+
name: 'session_id',
23+
type: AdminForthDataTypes.STRING,
24+
},
25+
{
26+
name: 'created_at',
27+
type: AdminForthDataTypes.DATE,
28+
fillOnCreate: () => new Date(),
29+
},
30+
{
31+
name: 'prompt',
32+
type: AdminForthDataTypes.TEXT,
33+
},
34+
{
35+
name: 'response',
36+
type: AdminForthDataTypes.TEXT,
37+
},
38+
],
39+
} as AdminForthResourceInput;

0 commit comments

Comments
 (0)