Skip to content
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

standard delete support #183

Closed
wants to merge 3 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
32 changes: 32 additions & 0 deletions src/main/java/liquibase/ext/neo4j/generator/DeleteGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package liquibase.ext.neo4j.generator;

import liquibase.change.ChangeMetaData;
import liquibase.database.Database;
import liquibase.exception.ValidationErrors;
import liquibase.sql.Sql;
import liquibase.sql.UnparsedSql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.sqlgenerator.core.AbstractSqlGenerator;
import liquibase.statement.core.DeleteStatement;

public class DeleteGenerator extends AbstractSqlGenerator<DeleteStatement> {

@Override
public ValidationErrors validate(DeleteStatement deleteStatement, Database database,
SqlGeneratorChain<DeleteStatement> sqlGeneratorChain) {
return null;
}

@Override
public Sql[] generateSql(DeleteStatement deleteStatement, Database database,
SqlGeneratorChain<DeleteStatement> sqlGeneratorChain) {
String label = deleteStatement.getTableName();
String cypher = String.format("MATCH (n: %s)%nDELETE n", label);
return new Sql[]{new UnparsedSql(cypher)};
}

@Override
public int getPriority() {
return ChangeMetaData.PRIORITY_DEFAULT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
liquibase.ext.neo4j.generator.DeleteGenerator
24 changes: 24 additions & 0 deletions src/test/groovy/liquibase/ext/neo4j/Neo4jPluginTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,30 @@ CREATE (:SecretMovie {title: 'Neo4j 4.4 EE: A life story'});
}


def "run deletes"(){
given:
queryRunner.run("MERGE (:Person {name: 'Charles', firstName: 'Clarence'})")
String[] arguments = [
"--url", "jdbc:neo4j:${neo4jContainer.getBoltUrl()}",
"--username", "neo4j",
"--password", PASSWORD,
"--changeLogFile", "classpath:/changelog-delete.xml",
"update"
].toArray()

when:
Main.run(arguments)

then:
def rows = queryRunner.getRows("""
MATCH (p: Person)
RETURN Count(p) = 0 as result
""")
rows.size() == 1
rows[0] == ["result": true]
}


private static PrintStream mute() {
new PrintStream(Files.createTempFile("liquibase", "neo4j").toFile())
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/changelog-delete.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">

<changeSet id="delete" author="clarenced">
<comment>Deleting a person</comment>
<delete tableName="Person" />
</changeSet>
</databaseChangeLog>