Skip to content

Allow to skip the default migration creating the migrations table #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/files-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const loadMigrationFiles = async (
directory: string,
// tslint:disable-next-line no-empty
log: Logger = () => {},
skipCreateMigrationTable: boolean = false,
): Promise<Array<Migration>> => {
log(`Loading migrations from: ${directory}`)

Expand All @@ -31,8 +32,16 @@ export const loadMigrationFiles = async (
return []
}

const migrationFiles = [
path.join(__dirname, "migrations/0_create-migrations-table.sql"),
let migrationFiles = []

if (!skipCreateMigrationTable) {
migrationFiles.push(
path.join(__dirname, "migrations/0_create-migrations-table.sql"),
)
}

migrationFiles = [
...migrationFiles,
...fileNames.map((fileName) => path.resolve(directory, fileName)),
].filter(isValidFile)

Expand Down
2 changes: 1 addition & 1 deletion src/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function migrate(
if (typeof migrationsDirectory !== "string") {
throw new Error("Must pass migrations directory as a string")
}
const intendedMigrations = await loadMigrationFiles(migrationsDirectory, log)
const intendedMigrations = await loadMigrationFiles(migrationsDirectory, log, config.skipCreateMigrationTable)

if ("client" in dbConfig) {
// we have been given a client to use, it should already be connected
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export type Config = Partial<FullConfig>

export interface FullConfig {
readonly logger: Logger
readonly skipCreateMigrationTable: boolean
}

export class MigrationError extends Error {
Expand Down