Skip to content
Snippets Groups Projects
Commit abda4fd7 authored by npedot's avatar npedot
Browse files

adds drop constraints via changeset by table name

parent 33120010
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,17 @@ class Schema () {
fun constraint(name: String): Constraint? {
if (constraints().isEmpty()) return null
return constraints().filter { c -> c.name==name}.firstOrNull()
return constraints().filter { c -> c.name==name }.firstOrNull()
}
fun constraintById(id: String): Constraint? {
if (constraints().isEmpty()) return null
return constraints().filter { c -> c.id==id }.firstOrNull()
}
fun constraintByTable(name: String): Constraint? {
if (constraints().isEmpty()) return null
return constraints().filter { c -> c.source.table==name || c.target.table==name }.firstOrNull()
}
fun keys(tableName: String): List<Constraint> {
......
......@@ -23,15 +23,15 @@ class DropConstraint() {
this.schemaName = schemaName
}
infix fun name(constraintName: String) = apply {
infix fun name(constraintName: String) = apply {
this.constraintName = constraintName
}
infix fun type(type:String) {
infix fun type(type:String) = apply {
this.type = type
}
infix fun table(table:String) {
infix fun table(table:String) = apply {
this.tableName = table
}
}
\ No newline at end of file
......@@ -113,14 +113,19 @@ class ApplyChangeSetUseCase(val serializer: SerializerServiceI) {
fun dropConstraint(db:Database, dropConstraint: DropConstraint):Database {
if (db.schema.constraints().isEmpty()) return db
val c = db.schema.constraint(dropConstraint.constraintName)
.let { it -> if(it !=null) db.schema.constraints().remove(it)}
if (dropConstraint.tableName.isNotEmpty()) {
db.schema.constraintByTable(dropConstraint.tableName)
.let { it -> if (it != null) db.schema.constraints().remove(it) }
} else {
db.schema.constraint(dropConstraint.constraintName)
.let { it -> if (it != null) db.schema.constraints().remove(it) }
}
return db
}
fun dropMapping(db:Database, dropMapping: DropMapping):Database {
if (db.mappings == null || db.mappings!!.isEmpty()) return db
val c = db.mapping(dropMapping.name)
db.mapping(dropMapping.name)
.let { it -> if(it !=null) db.mappings!!.remove(it)}
return db
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment