Skip to content

Commit

Permalink
remove useMigrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Calder committed Oct 25, 2022
1 parent 296641c commit 9078d83
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 @@ -66,7 +66,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 @@ -123,7 +123,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) {
const createRequestContext = async (req: IncomingMessage, res: ServerResponse) =>
Expand Down Expand Up @@ -179,8 +179,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 @@ -338,7 +337,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 @@ -351,22 +351,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 @@ -122,7 +122,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 9078d83

Please sign in to comment.