-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from smooth-code/add-check-structure-command
feat: add check-structure command
- Loading branch information
Showing
14 changed files
with
1,282 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
lib/ | ||
db/ | ||
!test/__fixtures__/structure.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
requireEnv, | ||
getInsertsFromMigrations, | ||
getInsertsFromStructure, | ||
} from './utils' | ||
|
||
async function checkStructure(options) { | ||
const { structurePath, migrationsPath } = options | ||
requireEnv('development', options.env) | ||
|
||
const migrationsInFolder = await getInsertsFromMigrations(migrationsPath) | ||
const migrationsInStructure = await getInsertsFromStructure(structurePath) | ||
|
||
return migrationsInFolder.every( | ||
(insert, index) => migrationsInStructure[index] === insert, | ||
) | ||
} | ||
|
||
export default checkStructure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
env: { | ||
jest: true, | ||
}, | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
-- | ||
-- PostgreSQL database dump | ||
-- | ||
|
||
-- Dumped from database version 10.2 | ||
-- Dumped by pg_dump version 10.2 | ||
|
||
SET statement_timeout = 0; | ||
SET lock_timeout = 0; | ||
SET idle_in_transaction_session_timeout = 0; | ||
SET client_encoding = 'UTF8'; | ||
SET standard_conforming_strings = on; | ||
SET check_function_bodies = false; | ||
SET client_min_messages = warning; | ||
SET row_security = off; | ||
|
||
-- | ||
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: | ||
-- | ||
|
||
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; | ||
|
||
-- | ||
-- PostgreSQL database dump complete | ||
-- | ||
|
||
-- Knex migrations | ||
|
||
INSERT INTO knex_migrations(name, batch, migration_time) VALUES ('20180207153033_migration_1.js', 1, NOW()); | ||
INSERT INTO knex_migrations(name, batch, migration_time) VALUES ('20180207153040_migration_2.js', 1, NOW()); | ||
INSERT INTO knex_migrations(name, batch, migration_time) VALUES ('20180207153050_migration_3.js', 1, NOW()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import path from 'path' | ||
import { getInsertsFromMigrations, getInsertsFromStructure } from '../src/utils' | ||
|
||
describe('#getInsertsFromMigrations', () => { | ||
it('without an existing directory, it should return an empty array', async () => { | ||
const inserts = await getInsertsFromMigrations( | ||
'/something-that-does-not-exist', | ||
) | ||
expect(inserts).toEqual([]) | ||
}) | ||
|
||
it('should read migrations from folder', async () => { | ||
const inserts = await getInsertsFromMigrations( | ||
path.join(__dirname, '__fixtures__/migrations'), | ||
) | ||
expect(inserts).toEqual([ | ||
`INSERT INTO knex_migrations(name, batch, migration_time) VALUES ('20180207153033_migration_1.js', 1, NOW());`, | ||
`INSERT INTO knex_migrations(name, batch, migration_time) VALUES ('20180207153040_migration_2.js', 1, NOW());`, | ||
]) | ||
}) | ||
}) | ||
|
||
describe('#getInsertsFromStructure', () => { | ||
it('without an existing file, it should return an empty array', async () => { | ||
const inserts = await getInsertsFromStructure( | ||
'/something-that-does-not-exist', | ||
) | ||
expect(inserts).toEqual([]) | ||
}) | ||
|
||
it('should read migrations from structure', async () => { | ||
const inserts = await getInsertsFromStructure( | ||
path.join(__dirname, '__fixtures__/structure.sql'), | ||
) | ||
expect(inserts).toEqual([ | ||
`INSERT INTO knex_migrations(name, batch, migration_time) VALUES ('20180207153033_migration_1.js', 1, NOW());`, | ||
`INSERT INTO knex_migrations(name, batch, migration_time) VALUES ('20180207153040_migration_2.js', 1, NOW());`, | ||
`INSERT INTO knex_migrations(name, batch, migration_time) VALUES ('20180207153050_migration_3.js', 1, NOW());`, | ||
]) | ||
}) | ||
}) |
Oops, something went wrong.