Skip to content

Commit d572865

Browse files
committed
remove --reset-db
1 parent 20c515b commit d572865

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed

.changeset/plenty-books-share.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@keystone-6/core': major
3+
---
4+
5+
Removes `--reset-db` from `keystone dev`, use `keystone prisma db push --force-reset` to reset your database

docs/pages/docs/guides/cli.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,18 @@ We strongly recommend enabling migrations if you are going to run your app in pr
129129

130130
### Resetting the database
131131

132-
From time to time, in development you may want to reset the database and recreate it from scratch. You can do this by passing the `--reset-db` flag:
132+
From time to time, in development you may want to reset the database and recreate it from scratch.
133+
You can do this by using Prisma:
133134

134135
```bash
135-
$ keystone dev --reset-db
136+
$ keystone prisma db push --force-reset
136137
```
137138

138139
{% hint kind="error" %}
139140
Doing this will destroy your database, including all data
140141
{% /hint %}
141142

142-
This is mainly useful early in a project's development lifecycle, when you want to test database initialisation scripts or create a fresh set of test data.
143+
This is typically useful early in a project's development lifecycle, when you want to test database initialisation scripts or create a fresh set of test data.
143144

144145
## postinstall
145146

packages/core/src/lib/migrations.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export async function pushPrismaSchemaToDatabase(
6666
shadowDbUrl: string | undefined,
6767
schema: string,
6868
schemaPath: string,
69-
resetDb = false
69+
resetDb: boolean
7070
) {
7171
const before = Date.now();
7272
await ensureDatabaseExists(dbUrl, path.dirname(schemaPath));
@@ -181,7 +181,6 @@ export async function deployMigrations(dbUrl: string) {
181181
});
182182
}
183183

184-
// TODO: don't have process.exit calls here
185184
export async function devMigrations(
186185
dbUrl: string,
187186
shadowDbUrl: string | undefined,

packages/core/src/scripts/cli.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export type Flags = {
1111
fix: boolean; // TODO: remove, deprecated
1212
frozen: boolean;
1313
prisma: boolean;
14-
resetDb: boolean;
1514
server: boolean;
1615
ui: boolean;
1716
withMigrations: boolean;
@@ -82,7 +81,7 @@ export async function cli(cwd: string, argv: string[]) {
8281
if (command === 'dev') {
8382
return dev(
8483
cwd,
85-
defaultFlags(flags, { dbPush: true, prisma: true, resetDb: false, server: true, ui: true })
84+
defaultFlags(flags, { dbPush: true, prisma: true, server: true, ui: true })
8685
);
8786
}
8887

packages/core/src/scripts/run/dev.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ export async function dev(
8080
{
8181
dbPush,
8282
prisma,
83-
resetDb,
8483
server,
8584
ui,
86-
}: Pick<Flags, 'dbPush' | 'prisma' | 'resetDb' | 'server' | 'ui'>
85+
}: Pick<Flags, 'dbPush' | 'prisma' | 'server' | 'ui'>
8786
) {
8887
console.log('✨ Starting Keystone');
8988
const app = server ? express() : null;
@@ -135,7 +134,6 @@ export async function dev(
135134
server,
136135
prisma,
137136
dbPush,
138-
resetDb,
139137
});
140138

141139
if (configWithHTTP?.server?.extendHttpServer && httpServer && context) {
@@ -375,12 +373,11 @@ async function setupInitialKeystone(
375373
cwd: string,
376374
options: {
377375
dbPush: boolean;
378-
resetDb: boolean;
379376
prisma: boolean;
380377
server: boolean;
381378
}
382379
) {
383-
const { dbPush, resetDb, prisma, server } = options;
380+
const { dbPush, prisma, server } = options;
384381
const { graphQLSchema, adminMeta, getKeystone } = createSystem(config);
385382

386383
// Make local storage folders if used
@@ -403,15 +400,15 @@ async function setupInitialKeystone(
403400
config.db.shadowDatabaseUrl,
404401
prismaSchema,
405402
getSchemaPaths(cwd).prisma,
406-
resetDb
403+
false
407404
);
408405
} else if (dbPush) {
409406
await pushPrismaSchemaToDatabase(
410407
config.db.url,
411408
config.db.shadowDatabaseUrl,
412409
prismaSchema,
413410
getSchemaPaths(cwd).prisma,
414-
resetDb
411+
false
415412
);
416413
} else {
417414
console.log('⚠️ Skipping database schema push');

packages/core/src/scripts/tests/migrations.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@ setSkipWatching();
1818
const dbUrl = 'file:./app.db';
1919

2020
async function setupAndStopDevServerForMigrations(cwd: string, resetDb: boolean = false) {
21-
const stopServer = (await runCommand(
22-
cwd,
23-
`dev${resetDb ? ' --reset-db' : ''}`
24-
)) as () => Promise<void>;
25-
await stopServer();
21+
if (resetDb) {
22+
await ((await runCommand(cwd, 'prisma db push --force-reset')) as () => Promise<void>)();
23+
}
24+
await (((await runCommand(cwd, 'dev')) as () => Promise<void>)());
2625
}
2726

2827
function getPrismaClient(cwd: string) {
29-
const prismaClient = new (requirePrismaClient(cwd).PrismaClient)({
28+
return new (requirePrismaClient(cwd).PrismaClient)({
3029
datasources: { sqlite: { url: dbUrl } },
3130
});
32-
return prismaClient;
3331
}
3432

3533
async function getGeneratedMigration(

0 commit comments

Comments
 (0)