From 599e0fa728f62f9e9b72ad3d7026d4ff04f9b5e5 Mon Sep 17 00:00:00 2001 From: Josh Calder Date: Tue, 25 Oct 2022 18:42:13 +0100 Subject: [PATCH] remove useMigrations --- .../keystone-server/keystone.ts | 2 -- .../keystone-server/keystone.ts | 2 -- examples/feature-boilerplate/keystone.ts | 2 -- packages/core/src/scripts/run/dev.ts | 27 +++++++++---------- .../fixtures/no-fields-with-migrations.ts | 1 - .../fixtures/one-field-with-migrations.ts | 1 - .../fixtures/two-fields-with-migrations.ts | 1 - packages/core/src/types/config/index.ts | 1 - 8 files changed, 12 insertions(+), 25 deletions(-) diff --git a/examples/document-field-customisation/keystone-server/keystone.ts b/examples/document-field-customisation/keystone-server/keystone.ts index 65f7139fa3c..5cb12907575 100644 --- a/examples/document-field-customisation/keystone-server/keystone.ts +++ b/examples/document-field-customisation/keystone-server/keystone.ts @@ -6,8 +6,6 @@ import { Context, TypeInfo } from '.keystone/types'; const db: KeystoneConfig['db'] = { provider: 'sqlite', - // You should use migrations in production environments - useMigrations: false, url: process.env.DATABASE_URL || 'file:./database.db', async onConnect(context: Context) { if (process.argv.includes('--seed-database')) { diff --git a/examples/e2e-boilerplate/keystone-server/keystone.ts b/examples/e2e-boilerplate/keystone-server/keystone.ts index 65f7139fa3c..5cb12907575 100644 --- a/examples/e2e-boilerplate/keystone-server/keystone.ts +++ b/examples/e2e-boilerplate/keystone-server/keystone.ts @@ -6,8 +6,6 @@ import { Context, TypeInfo } from '.keystone/types'; const db: KeystoneConfig['db'] = { provider: 'sqlite', - // You should use migrations in production environments - useMigrations: false, url: process.env.DATABASE_URL || 'file:./database.db', async onConnect(context: Context) { if (process.argv.includes('--seed-database')) { diff --git a/examples/feature-boilerplate/keystone.ts b/examples/feature-boilerplate/keystone.ts index 65f7139fa3c..5cb12907575 100644 --- a/examples/feature-boilerplate/keystone.ts +++ b/examples/feature-boilerplate/keystone.ts @@ -6,8 +6,6 @@ import { Context, TypeInfo } from '.keystone/types'; const db: KeystoneConfig['db'] = { provider: 'sqlite', - // You should use migrations in production environments - useMigrations: false, url: process.env.DATABASE_URL || 'file:./database.db', async onConnect(context: Context) { if (process.argv.includes('--seed-database')) { diff --git a/packages/core/src/scripts/run/dev.ts b/packages/core/src/scripts/run/dev.ts index 2d887fcf9b4..305a56a2901 100644 --- a/packages/core/src/scripts/run/dev.ts +++ b/packages/core/src/scripts/run/dev.ts @@ -8,7 +8,7 @@ import fs from 'fs-extra'; import chalk from 'chalk'; import esbuild, { BuildFailure, BuildResult } from 'esbuild'; import { generateAdminUI } from '../../admin-ui/system'; -import { devMigrations, pushPrismaSchemaToDatabase } from '../../lib/migrations'; +import { pushPrismaSchemaToDatabase } from '../../lib/migrations'; import { createSystem } from '../../lib/createSystem'; import { getEsbuildConfig, loadBuiltConfig } from '../../lib/config/loadConfig'; import { defaults } from '../../lib/config/defaults'; @@ -65,7 +65,7 @@ export function setSkipWatching() { shouldWatch = false; } -export const dev = async (cwd: string, shouldDropDatabase: boolean) => { +export const dev = async (cwd: string, shouldDropDatabase: boolean, pushDb: boolean) => { console.log('✨ Starting Keystone'); const app = express(); @@ -122,7 +122,7 @@ export const dev = async (cwd: string, shouldDropDatabase: boolean) => { apolloServer, prismaClientModule, ...rest - } = await setupInitialKeystone(config, cwd, shouldDropDatabase); + } = await setupInitialKeystone(config, cwd, shouldDropDatabase, pushDb); if (configWithHTTP?.server?.extendHttpServer) { configWithHTTP.server.extendHttpServer(httpServer, context, graphQLSchema); @@ -171,8 +171,7 @@ export const dev = async (cwd: string, shouldDropDatabase: boolean) => { // and aren't written into the prisma schema since we check whether the prisma schema has changed above if ( newConfig.db.enableLogging !== config.db.enableLogging || - newConfig.db.url !== config.db.url || - newConfig.db.useMigrations !== config.db.useMigrations + newConfig.db.url !== config.db.url ) { console.log('Your db config has changed, please restart Keystone'); process.exit(1); @@ -339,7 +338,8 @@ export const dev = async (cwd: string, shouldDropDatabase: boolean) => { async function setupInitialKeystone( config: KeystoneConfig, cwd: string, - shouldDropDatabase: boolean + shouldDropDatabase: boolean, + pushDb: boolean ) { const { graphQLSchema, adminMeta, getKeystone } = createSystem(config); @@ -352,15 +352,7 @@ async function setupInitialKeystone( let migrationPromise: Promise; // Set up the Database - if (config.db.useMigrations) { - migrationPromise = devMigrations( - config.db.url, - config.db.shadowDatabaseUrl, - prismaSchema, - getSchemaPaths(cwd).prisma, - shouldDropDatabase - ); - } else { + if (pushDb) { migrationPromise = pushPrismaSchemaToDatabase( config.db.url, config.db.shadowDatabaseUrl, @@ -368,6 +360,11 @@ async function setupInitialKeystone( getSchemaPaths(cwd).prisma, shouldDropDatabase ); + } else { + const skipDBPush = async () => { + console.log('⚠️ Skipping database schema push'); + }; + migrationPromise = skipDBPush(); } await Promise.all([prismaClientGenerationPromise, migrationPromise]); diff --git a/packages/core/src/scripts/tests/fixtures/no-fields-with-migrations.ts b/packages/core/src/scripts/tests/fixtures/no-fields-with-migrations.ts index 956fe3e2833..700231dfa44 100644 --- a/packages/core/src/scripts/tests/fixtures/no-fields-with-migrations.ts +++ b/packages/core/src/scripts/tests/fixtures/no-fields-with-migrations.ts @@ -5,7 +5,6 @@ export default config({ db: { provider: 'sqlite', url: 'file:./app.db', - useMigrations: true, }, ui: { isDisabled: true }, lists: { diff --git a/packages/core/src/scripts/tests/fixtures/one-field-with-migrations.ts b/packages/core/src/scripts/tests/fixtures/one-field-with-migrations.ts index 8089cd3bac7..f45db094008 100644 --- a/packages/core/src/scripts/tests/fixtures/one-field-with-migrations.ts +++ b/packages/core/src/scripts/tests/fixtures/one-field-with-migrations.ts @@ -6,7 +6,6 @@ export default config({ db: { provider: 'sqlite', url: 'file:./app.db', - useMigrations: true, }, ui: { isDisabled: true }, lists: { diff --git a/packages/core/src/scripts/tests/fixtures/two-fields-with-migrations.ts b/packages/core/src/scripts/tests/fixtures/two-fields-with-migrations.ts index edb5c3d23f1..dfbb2f1ca23 100644 --- a/packages/core/src/scripts/tests/fixtures/two-fields-with-migrations.ts +++ b/packages/core/src/scripts/tests/fixtures/two-fields-with-migrations.ts @@ -6,7 +6,6 @@ export default config({ db: { provider: 'sqlite', url: 'file:./app.db', - useMigrations: true, }, ui: { isDisabled: true }, lists: { diff --git a/packages/core/src/types/config/index.ts b/packages/core/src/types/config/index.ts index ee89865852e..1954c0e353f 100644 --- a/packages/core/src/types/config/index.ts +++ b/packages/core/src/types/config/index.ts @@ -116,7 +116,6 @@ export type DatabaseConfig = { url: string; shadowDatabaseUrl?: string; onConnect?: (args: KeystoneContext) => Promise; - useMigrations?: boolean; enableLogging?: boolean; idField?: IdFieldConfig; provider: DatabaseProvider;