fix: functions migrations
This commit is contained in:
@@ -37,7 +37,7 @@ data class Function(
|
||||
connection.sendQuery(up.script)
|
||||
|
||||
this::class.java.classLoader.getResource("sql/migration/insertFunction.sql")!!.readText().let {
|
||||
connection.selectOne<MigrationEntity>(it, listOf(up))?.let { function ->
|
||||
connection.selectOne<MigrationEntity>(it, listOf(up.name, up.getDefinition(), up.script, down.script))?.let { function ->
|
||||
executedAt = function.executedAt
|
||||
doExecute = Action.OK
|
||||
}
|
||||
|
||||
@@ -37,10 +37,12 @@ data class Migrations private constructor(
|
||||
private val queries: MutableMap<String, Query> = mutableMapOf(),
|
||||
private val functions: MutableMap<String, Function> = mutableMapOf()
|
||||
) {
|
||||
constructor(directory: File, connection: Connection): this(connection) {
|
||||
constructor(directory: File, connection: Connection): this(listOf(directory), connection)
|
||||
|
||||
constructor(directories: List<File>, connection: Connection): this(connection) {
|
||||
initDB()
|
||||
getMigrationFromDB()
|
||||
getMigrationFromDirectory(directory)
|
||||
getMigrationFromDirectory(directories)
|
||||
queries.forEach { (_, query) ->
|
||||
if (query.doExecute === null) {
|
||||
query.doExecute = Action.DOWN
|
||||
@@ -75,6 +77,15 @@ data class Migrations private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all migration from multiples Directories
|
||||
*/
|
||||
private fun getMigrationFromDirectory(directory: List<File>) {
|
||||
directory.forEach {
|
||||
getMigrationFromDirectory(it)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all migration from Directory
|
||||
*/
|
||||
|
||||
@@ -9,5 +9,3 @@ CREATE TABLE IF NOT EXISTS migration.functions
|
||||
down text NOT NULL,
|
||||
version int NOT NULL
|
||||
);
|
||||
|
||||
CREATE SEQUENCE IF NOT EXISTS migration.version_seq;
|
||||
@@ -1 +0,0 @@
|
||||
SELECT nextval('migration.version_seq');
|
||||
@@ -1,3 +1,7 @@
|
||||
INSERT INTO migration.functions as f (filename, definition, executed_at, up, down, version)
|
||||
VALUES (?, ?, now(), ?, ?, ?)
|
||||
VALUES (?, ?, now(), ?, ?, (
|
||||
select coalesce(max(version), 0)+1
|
||||
from migration.functions f2
|
||||
where filename = f2.filename
|
||||
))
|
||||
RETURNING to_json(f);
|
||||
@@ -1,3 +1,7 @@
|
||||
INSERT INTO migration.history as h (filename, executed_at, up, down, version)
|
||||
VALUES (?, now(), ?, ?, nextval('migration.version_seq'))
|
||||
VALUES (?, now(), ?, ?, (
|
||||
select coalesce(max(version), 0)+1
|
||||
from migration.history f2
|
||||
where filename = f2.filename
|
||||
))
|
||||
RETURNING to_json(h);
|
||||
|
||||
Reference in New Issue
Block a user