-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrong detection of serial types on columns with multiple constraints (#…
…179) * Updated sql query * Added test to cover the issue Co-authored-by: Ivan Vakhrushev <i.vakhrushev@banki.ru>
- Loading branch information
Showing
8 changed files
with
197 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ithub/mfvanek/pg/support/statements/CreateTableWithCheckConstraintOnSerialPrimaryKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2019-2022. Ivan Vakhrushev and others. | ||
* https://github.com/mfvanek/pg-index-health | ||
* | ||
* This file is a part of "pg-index-health" - a Java library for | ||
* analyzing and maintaining indexes health in PostgreSQL databases. | ||
* | ||
* Licensed under the Apache License 2.0 | ||
*/ | ||
|
||
package io.github.mfvanek.pg.support.statements; | ||
|
||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import javax.annotation.Nonnull; | ||
|
||
public class CreateTableWithCheckConstraintOnSerialPrimaryKey extends AbstractDbStatement { | ||
|
||
public CreateTableWithCheckConstraintOnSerialPrimaryKey(@Nonnull final String schemaName) { | ||
super(schemaName); | ||
} | ||
|
||
@Override | ||
public void execute(@Nonnull final Statement statement) throws SQLException { | ||
statement.execute(String.format("create table if not exists %1$s.another_table(" + | ||
"id bigserial primary key, " + | ||
"constraint not_reserved_id check (id > 1000), " + | ||
"constraint less_than_million check (id < 1000000));", | ||
schemaName)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...fvanek/pg/support/statements/CreateTableWithSerialPrimaryKeyReferencesToAnotherTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2019-2022. Ivan Vakhrushev and others. | ||
* https://github.com/mfvanek/pg-index-health | ||
* | ||
* This file is a part of "pg-index-health" - a Java library for | ||
* analyzing and maintaining indexes health in PostgreSQL databases. | ||
* | ||
* Licensed under the Apache License 2.0 | ||
*/ | ||
|
||
package io.github.mfvanek.pg.support.statements; | ||
|
||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import javax.annotation.Nonnull; | ||
|
||
public class CreateTableWithSerialPrimaryKeyReferencesToAnotherTable extends AbstractDbStatement { | ||
|
||
public CreateTableWithSerialPrimaryKeyReferencesToAnotherTable(@Nonnull final String schemaName) { | ||
super(schemaName); | ||
} | ||
|
||
@Override | ||
public void execute(@Nonnull final Statement statement) throws SQLException { | ||
statement.execute(String.format("create table if not exists %1$s.test_table(" + | ||
"id bigserial, " + | ||
"num bigserial, " + | ||
"constraint test_table_pkey_id primary key (id), " + | ||
"constraint test_table_fkey_other_id foreign key (id) references %1$s.another_table (id), " + | ||
"constraint test_table_fkey_one_more_id foreign key (id) references %1$s.one_more_table (id));", | ||
schemaName)); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/test/java/io/github/mfvanek/pg/support/statements/CreateTableWithUniqueSerialColumn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2019-2022. Ivan Vakhrushev and others. | ||
* https://github.com/mfvanek/pg-index-health | ||
* | ||
* This file is a part of "pg-index-health" - a Java library for | ||
* analyzing and maintaining indexes health in PostgreSQL databases. | ||
* | ||
* Licensed under the Apache License 2.0 | ||
*/ | ||
|
||
package io.github.mfvanek.pg.support.statements; | ||
|
||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import javax.annotation.Nonnull; | ||
|
||
public class CreateTableWithUniqueSerialColumn extends AbstractDbStatement { | ||
|
||
public CreateTableWithUniqueSerialColumn(@Nonnull final String schemaName) { | ||
super(schemaName); | ||
} | ||
|
||
@Override | ||
public void execute(@Nonnull final Statement statement) throws SQLException { | ||
statement.execute(String.format("create table if not exists %1$s.one_more_table(" + | ||
"id bigserial, " + | ||
"constraint unique_id unique (id), " + | ||
"constraint not_reserved_id check (id > 1000), " + | ||
"constraint less_than_million check (id < 1000000));", | ||
schemaName)); | ||
} | ||
} |