Skip to content

Commit

Permalink
remove useMigrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Calder committed Nov 30, 2022
1 parent 3b0475f commit 599e0fa
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Context, TypeInfo } from '.keystone/types';

const db: KeystoneConfig<TypeInfo>['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')) {
Expand Down
2 changes: 0 additions & 2 deletions examples/e2e-boilerplate/keystone-server/keystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Context, TypeInfo } from '.keystone/types';

const db: KeystoneConfig<TypeInfo>['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')) {
Expand Down
2 changes: 0 additions & 2 deletions examples/feature-boilerplate/keystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Context, TypeInfo } from '.keystone/types';

const db: KeystoneConfig<TypeInfo>['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')) {
Expand Down
27 changes: 12 additions & 15 deletions packages/core/src/scripts/run/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -352,22 +352,19 @@ async function setupInitialKeystone(
let migrationPromise: Promise<void>;

// 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,
prismaSchema,
getSchemaPaths(cwd).prisma,
shouldDropDatabase
);
} else {
const skipDBPush = async () => {
console.log('⚠️ Skipping database schema push');
};
migrationPromise = skipDBPush();
}

await Promise.all([prismaClientGenerationPromise, migrationPromise]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export default config({
db: {
provider: 'sqlite',
url: 'file:./app.db',
useMigrations: true,
},
ui: { isDisabled: true },
lists: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default config({
db: {
provider: 'sqlite',
url: 'file:./app.db',
useMigrations: true,
},
ui: { isDisabled: true },
lists: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default config({
db: {
provider: 'sqlite',
url: 'file:./app.db',
useMigrations: true,
},
ui: { isDisabled: true },
lists: {
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/types/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export type DatabaseConfig<TypeInfo extends BaseKeystoneTypeInfo> = {
url: string;
shadowDatabaseUrl?: string;
onConnect?: (args: KeystoneContext<TypeInfo>) => Promise<void>;
useMigrations?: boolean;
enableLogging?: boolean;
idField?: IdFieldConfig;
provider: DatabaseProvider;
Expand Down

0 comments on commit 599e0fa

Please sign in to comment.