Skip to content

Make doesTableExist check for table in current search path #1

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

Closed
wants to merge 24 commits into from
Closed
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
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

4 changes: 0 additions & 4 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
src/__tests__
src/__unit__
src/
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Changelog

## V4
## 5.1.0

- Validate migration ordering when loading files (instead of when applying migrations)
- Expose `loadMigrationFiles` publicly, which can be used to validate files in e.g. a pre-push hook
- Add `pg-validate-migrations` bin script

## 5.0.0

- [BREAKING] Update `pg` to version 8. See the [pg changelog](https://github.com/brianc/node-postgres/blob/master/CHANGELOG.md#pg800) for details.

## 4.0.0

- [BREAKING] Updated whole project to TypeScript
- some types might differ, no functional change
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {createDb, migrate} from "postgres-migrations"

async function() {
const dbConfig = {
database: "database-name"
database: "database-name",
user: "postgres",
password: "password",
host: "localhost",
Expand Down Expand Up @@ -76,6 +76,16 @@ async function() {
}
```

### Validating migration files

Occasionally, if two people are working on the same codebase independently, they might both create a migration at the same time. For example, `5_add-table.sql` and `5_add-column.sql`. If these both get pushed, there will be a conflict.

While the migration system will notice this and refuse to apply the migrations, it can be useful to catch this as early as possible.

The `loadMigrationFiles` function can be used to check if the migration files satisfy the rules.

Alternatively, use the `pg-validate-migrations` bin script: `pg-validate-migrations "path/to/migration/files"`.

## Design decisions

### No down migrations
Expand Down Expand Up @@ -196,7 +206,7 @@ migrations
└ 00003_alter-initial-tables-again.js
```

Migrations will be performed in the order of the ids.
Migrations will be performed in the order of the ids. If ids are not consecutive or if multiple migrations have the same id, the migration run will fail.

Note that file names cannot be changed later.

Expand Down Expand Up @@ -250,4 +260,4 @@ pg.types.setTypeParser(DATATYPE_DATE, val => {

## Developing `postgres-migrations`

The tests require Docker to be installed.
The tests require Docker to be installed. It probably helps to `docker pull postgres:9.4`.
3 changes: 1 addition & 2 deletions ava.config.js → ava.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export default {
compileEnhancements: false,
module.exports = {
extensions: ["ts"],
require: ["ts-node/register"],
}
6 changes: 6 additions & 0 deletions ava.config.integration.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const baseConfig = require("./ava.config.cjs")

module.exports = {
...baseConfig,
files: ["src/**/__tests__/**/*.ts", "!src/**/__tests__/**/fixtures/**/*"],
}
6 changes: 0 additions & 6 deletions ava.config.integration.js

This file was deleted.

6 changes: 6 additions & 0 deletions ava.config.unit.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const baseConfig = require("./ava.config.cjs")

module.exports = {
...baseConfig,
files: ["src/**/__unit__/**/*.ts", "!src/**/__unit__/**/fixtures/**/*"],
}
6 changes: 0 additions & 6 deletions ava.config.unit.js

This file was deleted.

Loading