@@ -36,6 +36,19 @@ describe('Podil', async () => {
3636 assert . strictEqual ( nameFromDb , 'test data' )
3737 } )
3838
39+ it ( 'should apply migration only once' , async ( ) => {
40+ // given
41+ await podil . migrate ( connectionString , { migrationsDir : './test/PodilTest/single_migration' } )
42+
43+ // when running the second time nothing should happen
44+ await podil . migrate ( connectionString , { migrationsDir : './test/PodilTest/single_migration' } )
45+
46+ // then
47+ const result = await client . query ( 'SELECT name FROM test_table' )
48+ const nameFromDb = result . rows [ 0 ] . name
49+ assert . strictEqual ( nameFromDb , 'test data' )
50+ } )
51+
3952 it ( 'should apply multiple migrations' , async ( ) => {
4053 // when
4154 await podil . migrate ( connectionString , { migrationsDir : './test/PodilTest/two_migrations' } )
@@ -56,6 +69,8 @@ describe('Podil', async () => {
5669 checksum CHAR(64) NOT NULL
5770 )`
5871 )
72+ await client . query ( 'CREATE TABLE test_table (name VARCHAR(255) PRIMARY KEY)' )
73+ await client . query ( 'INSERT INTO test_table values (\'test data\')' )
5974 await client . query (
6075 'INSERT INTO podil_migrations(name, checksum) VALUES($1, $2)' ,
6176 [ '01__init.sql' , '06ea2d756243a1e96ebf74d971812d3fe678b6888108bc44b929ae0e560f0924' ]
@@ -65,9 +80,9 @@ describe('Podil', async () => {
6580 await podil . migrate ( connectionString , { migrationsDir : './test/PodilTest/two_migrations' } )
6681
6782 // then
68- const result = await client . query ( 'SELECT name FROM test_table' )
69- const nameFromDb = result . rows [ 0 ] . name
70- assert . strictEqual ( nameFromDb , 'test data ' )
83+ const result = await client . query ( 'SELECT test FROM test_table' )
84+ const nameFromDb = result . rows [ 0 ] . test
85+ assert . strictEqual ( nameFromDb , 'value from the second script ' )
7186 } )
7287
7388 it ( 'should fail to apply migration when checksum check fails' , async ( ) => {
0 commit comments