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

Bugfixes #271

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ public class PgDumpLoader { //NOPMD
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);

/**
* Pattern for testing whether it is CREATE POLICY statement.
* Pattern for testing whether it is a DISABLE TRIGGER statement.
*/
private static final Pattern PATTERN_DISABLE_TRIGGER = Pattern.compile(
"ALTER\\s+TABLE+\\s+\\w+.+\\w+\\s+DISABLE+\\s+TRIGGER+\\s+\\w+.*$",
"ALTER\\s+TABLE+\\s+\"?\\w+\"?.+\"?\\w+\"?\\s+DISABLE+\\s+TRIGGER+\\s+\\w+.*$",
Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
/**
* Pattern for testing whether it is CREATE RULE statement.
Expand Down Expand Up @@ -251,7 +251,7 @@ public static PgDatabase loadDatabaseSchema(final InputStream inputStream,
CreateTriggerParser.parse(
database, statement, ignoreSlonyTriggers);
} else if ( PATTERN_DISABLE_TRIGGER.matcher(statement).matches()) {
CreateTriggerParser.parseDisable(database, statement);
CreateTriggerParser.parseDisable(database, statement, ignoreSlonyTriggers);
} else if (PATTERN_CREATE_FUNCTION.matcher(statement).matches()) {
CreateFunctionParser.parse(database, statement);
} else if (PATTERN_CREATE_TYPE.matcher(statement).matches()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void parse(final PgDatabase database,

rule.setQuery(query);

final String schemaName = ParserUtils.getSchemaName(ruleName, database);
final String schemaName = ParserUtils.getSchemaName(relationName, database);
final PgSchema schema = database.getSchema(schemaName);

if (schema == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public static void parse(final PgDatabase database,
if (parser.expectOptional(referencing)) {
trigger.setReferencing("\t"+referencing);

while( !parser.getSubString(parser.getPosition()-5, parser.getPosition()-4).equals(System.getProperty("line.separator"))){
while(parser.getSubString(parser.getPosition(), parser.getPosition()+3).equals("NEW") ||
parser.getSubString(parser.getPosition(), parser.getPosition()+3).equals("OLD") ){
parseReferencing(parser,trigger);

}
}
}

if (parser.expectOptional("FOR")) {
Expand All @@ -107,11 +107,7 @@ public static void parse(final PgDatabase database,
parser.expect("EXECUTE", "PROCEDURE");
trigger.setFunction(parser.getRest());

final boolean ignoreSlonyTrigger = ignoreSlonyTriggers
&& ("_slony_logtrigger".equals(trigger.getName())
|| "_slony_denyaccess".equals(trigger.getName()));

if (!ignoreSlonyTrigger) {
if (!ignoreSlonyTrigger(trigger.getName(), ignoreSlonyTriggers)) {
final PgSchema schema = database.getSchema(
ParserUtils.getSchemaName(relationName, database));
schema.getRelation(trigger.getRelationName()).addTrigger(trigger);
Expand All @@ -138,7 +134,7 @@ private static void parseReferencing(Parser parser, PgTrigger trigger) {
}

public static void parseDisable(final PgDatabase database,
final String statement) {
final String statement, final boolean ignoreSlonyTriggers) {
final Parser parser = new Parser(statement);
parser.expect("ALTER", "TABLE");

Expand All @@ -150,9 +146,19 @@ public static void parseDisable(final PgDatabase database,
trigger.setName(objectName);

trigger.setRelationName(ParserUtils.getObjectName(tableName));

final PgSchema schema = database.getSchema(

if (!ignoreSlonyTrigger(trigger.getName(), ignoreSlonyTriggers)) {
final PgSchema schema = database.getSchema(
ParserUtils.getSchemaName(tableName, database));
schema.getRelation(trigger.getRelationName()).getTrigger(objectName).setDisable(true);
}
}
private static boolean ignoreSlonyTrigger(String trigger, Boolean ignore) {
return ignore && (
"_slony_logtrigger".equals(trigger) ||
"_slony_denyaccess".equals(trigger) ||
"_slony_truncatedeny".equals(trigger) ||
"_slony_truncatetrigger".equals(trigger)
);
}
}
18 changes: 7 additions & 11 deletions src/main/java/cz/startnet/utils/pgdiff/parsers/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,22 @@ public boolean expect(final String word, final boolean optional) {

/**
* Checks whether string contains at current position sequence of the words.
* Only advance position if all words are found.
*
* @param words array of words
*
* @return true if whole sequence was found, otherwise false
*/
public boolean expectOptional(final String... words) {
final boolean found = expect(words[0], true);

if (!found) {
return false;
}

for (int i = 1; i < words.length; i++) {
skipWhitespace();
expect(words[i]);
int startpos = position;
for (int i = 0; i < words.length; i++) {
if (!expect(words[i], true)) {
position = startpos;
return false;
}
}

return true;
}

/**
* Moves position in the string to next non-whitespace string.
*/
Expand Down