You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-16Lines changed: 18 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,35 +37,37 @@ Why AdminForth:
37
37
38
38
## Project initialisation
39
39
40
-
To create an AdminForth project, run:
40
+
AdminForth supports two setup paths:
41
41
42
-
```bash
43
-
npx adminforth create-app
44
-
```
42
+
### Path 1: Existing database
45
43
46
-
During the interactive initialization process, AdminForth will ask you to provide a local database URL.
44
+
Use this path when you already have a database and your own schema or migrations. Provide your database URL with `--db`, or enter it when the CLI asks `Please specify the database URL to use`.
47
45
48
-
### Integrating AdminForth into your existing application
If you want to build an admin panel for an existing project that already has a database with tables, you can provide the connection URL to your existing development database, such as a local or deployed one.
51
+
When you provide your own database URL, AdminForth connects to your database but does not create Prisma schema or migrations for it. The generated project README includes the SQL or schema notes needed to add the required `adminuser` table with your own migration tool.
51
52
52
-
After that, you may want to generate AdminForth resource files from your existing database tables:
53
+
After project creation, generate AdminForth resource files from your existing tables:
53
54
54
55
```bash
55
56
npx adminforth resource
56
57
```
57
58
58
-
Resource files are needed for AdminForth to “know” about your tables and define how to work with them.
59
+
### Path 2: New database
59
60
60
-
Use the command above every time you add new tables or change their schema.
61
+
Use this path when you want AdminForth to scaffold a standalone app with a new local SQLite database. Omit `--db`, or accept the default `sqlite://.db.sqlite` value in the interactive prompt:
61
62
62
-
### Starting from scratch
63
-
64
-
If you do not have a database yet, start an empty local database, for example PostgreSQL in Docker, and provide its URL to the AdminForth CLI.
65
-
66
-
If the adminforth CLI does not detect any tables, it will suggest adding Prisma as a migration tool. Prisma is not related to AdminForth, but it is one of the most convenient migration tools.
For the new database path, the CLI can scaffold Prisma files and migration scripts for the default `sqlite://.db.sqlite` database. Please follow [getting started](https://adminforth.dev/docs/tutorial/gettingStarted/) for the full guide.
Copy file name to clipboardExpand all lines: adminforth/commands/createApp/templates/readme.md.hbs
+10Lines changed: 10 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,21 @@ Install dependencies:
6
6
{{packageManager}} install
7
7
```
8
8
9
+
{{#ifadminUserTableInstructions}}
10
+
Prepare the admin users table in your existing database before starting the app. AdminForth uses this table for back-office authentication, and your own migration tool should own this schema change:
11
+
12
+
{{{adminUserTableInstructions}}}
13
+
14
+
The generated app will seed the default `adminforth` / `adminforth` user on first start if the table is empty.
return'Create an `adminuser` collection with `id`, `email`, `password_hash`, `role`, and `created_at` fields. Keep `email` unique in your own schema/index setup.';
Copy file name to clipboardExpand all lines: adminforth/documentation/docs/tutorial/001-gettingStarted.md
+35-8Lines changed: 35 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,15 +21,38 @@ nvm use 20
21
21
22
22
## Creating an AdminForth Project
23
23
24
-
The recommended way to get started with AdminForth is via the **`create-app`** CLI, which scaffolds a basic fully functional back-office application. Apart boilerplate it creates one resource for users management.
24
+
The recommended way to get started with AdminForth is via the **`create-app`** CLI, which scaffolds a basic fully functional back-office application. Apart from boilerplate, it creates one resource for users management.
25
25
26
-
You can provide options directorly:
26
+
There are two common setup paths:
27
+
28
+
### Path 1: Existing Database
29
+
30
+
Use this path when you already have a database and your own schema or migrations. Pass your database URL with `--db`, or enter it when the CLI asks `Please specify the database URL to use`:
When you provide your own database URL, the CLI treats this as your own database. It does not create Prisma schema or Prisma migration scripts for that database. Instead, the generated project README contains the SQL or schema notes for adding the required `adminuser` table with your own migration tool.
37
+
38
+
After the project is created, navigate into it and generate resources from your existing tables:
39
+
40
+
```bash
41
+
cd myadmin
42
+
npx adminforth resource
43
+
```
44
+
45
+
Resource files are needed for AdminForth to know about your tables and define how to work with them. Use `npx adminforth resource` again when you add new tables or change their schema.
46
+
47
+
### Path 2: New Database
48
+
49
+
Use this path when you want AdminForth to scaffold a standalone app with a new local SQLite database. Omit `--db`, or accept the default `sqlite://.db.sqlite` value in the interactive prompt:
├── schema.prisma # Prisma schema file, generated only for the new database path
73
98
├── index.ts # Main entry point: configures AdminForth & starts the server
74
99
├── package.json # Project dependencies
75
100
├── pnpm-workspace.yaml
@@ -82,15 +107,15 @@ myadmin/
82
107
83
108
### Initial Migration & Future Migrations
84
109
85
-
> ☝️ CLI creates Prisma schema file for managing migrations in relational databases, however you are not forced to use it. Instead you are free to use your favourite or existing migration tool. In this case just ignore generated prisma file, and don't run migration command which will be suggested by CLI. However you have to ensure that your migration tool will generate required table `adminuser` with same fields and types for Admin Users resource to implmenet BackOffice authentication.
110
+
For the new database path, the CLI creates Prisma files for managing migrations. Prisma is not required by AdminForth itself, but it is a convenient migration tool for standalone projects that do not have database management yet.
86
111
87
112
CLI will suggest you a command to initialize the database with Prisma:
This will create a migration file in `migrations`and apply it to the database.
118
+
This will create a migration file and apply it to the database.
94
119
95
120
In future, when you need to add new resources, you need to modify `schema.prisma` (add models, change fields, etc.). After doing any modification you need to create a new migration using next command:
Other developers need to pull migration and run `pnpm migrate:local` to apply any unapplied migrations.
102
127
128
+
For the existing database path, use your own migration tool instead. The generated project README shows how to add the required `adminuser` table to your database.
0 commit comments