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

[DAT-17805] fixed PKSnapshotGenerator, removed unneeded classes #329

Merged
merged 3 commits into from
Jun 14, 2024
Merged
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
64 changes: 31 additions & 33 deletions src/main/java/liquibase/ext/bigquery/database/BigQueryDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import liquibase.executor.ExecutorService;
import liquibase.statement.core.GetViewDefinitionStatement;
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.Catalog;
import liquibase.structure.core.Schema;
import liquibase.structure.core.Sequence;
import liquibase.structure.core.Table;
import liquibase.structure.core.*;

import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -54,11 +51,6 @@ public int getPriority() {
return BIGQUERY_PRIORITY_DATABASE;
}

@Override
public boolean supportsDatabaseChangeLogHistory() {
return true;
}

@Override
public String correctObjectName(String objectName, Class<? extends DatabaseObject> objectType) {
if (Table.class.isAssignableFrom(objectType) && objectName.equalsIgnoreCase("DATABASECHANGELOGHISTORY")) {
Expand Down Expand Up @@ -100,29 +92,6 @@ public int getDatabaseMinorVersion() {
return BQDriver.DRIVER_MINOR_VERSION;
}

@Override
public boolean supports(Class<? extends DatabaseObject> object) {
if (Sequence.class.isAssignableFrom(object)) {
return false;
}
return super.supports(object);
}

@Override
public boolean supportsInitiallyDeferrableColumns() {
return false;
}

@Override
public boolean supportsDropTableCascadeConstraints() {
return false;
}

@Override
public boolean supportsTablespaces() {
return false;
}

@Override
protected String getQuotingStartCharacter() {
return "`";
Expand Down Expand Up @@ -153,6 +122,10 @@ public String getDefaultDriver(String url) {

return null;
}
@Override
public boolean supportsDatabaseChangeLogHistory() {
return true;
}

@Override
public boolean supportsSequences() {
Expand All @@ -165,12 +138,37 @@ public boolean supportsRestrictForeignKeys() {
}

@Override
public boolean supportsNotNullConstraintNames() {
return false;
}

public boolean supportsPrimaryKeyNames() {
return false;
}

@Override
public boolean supportsNotNullConstraintNames() {
public boolean supports(Class<? extends DatabaseObject> object) {
if (Sequence.class.isAssignableFrom(object)) {
return false;
}
if (UniqueConstraint.class.isAssignableFrom(object)) {
return false;
}
return super.supports(object);
}

@Override
public boolean supportsInitiallyDeferrableColumns() {
return false;
}

@Override
public boolean supportsDropTableCascadeConstraints() {
return false;
}

@Override
public boolean supportsTablespaces() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot
}
PrimaryKey returnKey = null;

String keyColumnUsageStatement = String.format("SELECT * FROM %s.INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE table_name = ?", schema.getSchema());
String keyColumnUsageStatement = String.format("SELECT * FROM %s.INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE CONSTRAINT_NAME = ?",
schema.getSchema());
Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database);
List<Map<String, ?>> maps = executor.queryForList(new RawParameterizedSqlStatement(keyColumnUsageStatement, searchTableName));
List<Map<String, ?>> maps = executor.queryForList(new RawParameterizedSqlStatement(keyColumnUsageStatement, example.getName()));
String columnName;
for (Map<String, ?> map : maps) {
columnName = Objects.toString(map.get("COLUMN_NAME"), null);
Expand Down Expand Up @@ -93,7 +94,8 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro
Schema schema = table.getSchema();

Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database);
String tableConstraintsStatement = String.format("SELECT * FROM %s.INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE table_name = ?", schema.getSchema());
String tableConstraintsStatement = String.format("SELECT * FROM %s.INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE " +
"CONSTRAINT_TYPE = 'PRIMARY KEY' AND table_name = ?", schema.getSchema());
List<Map<String, ?>> maps = executor.queryForList(new RawParameterizedSqlStatement(tableConstraintsStatement, table.getName()));

for (Map<String, ?> map : maps) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
liquibase.ext.bigquery.snapshot.jvm.BigQueryDatasetSnapshotGenerator
liquibase.ext.bigquery.snapshot.jvm.BigQueryUniqueConstraintSnapshotGenerator
liquibase.ext.bigquery.snapshot.jvm.BigQuerySequenceSnapshotGenerator
liquibase.ext.bigquery.snapshot.jvm.BigQueryViewSnapshotGenerator
liquibase.ext.bigquery.snapshot.jvm.BigQueryForeignKeySnapshotGenerator
liquibase.ext.bigquery.snapshot.jvm.BigQueryPrimaryKeySnapshotGenerator
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
liquibase.ext.bigquery.sqlgenerator.BigQueryAddColumnGenerator
liquibase.ext.bigquery.sqlgenerator.BigQueryAddForeignKeyConstraintGenerator
liquibase.ext.bigquery.sqlgenerator.BigQueryAddPrimaryKeyConstraintGenerator
liquibase.ext.bigquery.sqlgenerator.BigQueryDropForeignKeyConstraintGenerator
liquibase.ext.bigquery.sqlgenerator.BigQueryDropPrimaryKeyConstraintGenerator
liquibase.ext.bigquery.sqlgenerator.BigQueryCreateDatabaseChangeLogLockTableGenerator
liquibase.ext.bigquery.sqlgenerator.BigQueryCreateDatabaseChangeLogTableGenerator
liquibase.ext.bigquery.sqlgenerator.BigQueryDeleteGenerator
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
{
"snapshot": {
"objects": {
"liquibase.structure.core.Table": [
{
"table": {
"name": "test_table",
"primaryKey": "liquibase.structure.core.PrimaryKey.*"
}
}
],
"liquibase.structure.core.PrimaryKey": [
{
"primaryKey": {
"name": "test_table.pk$"
}
}
]
}
}
}
Loading