// Path: src/main/java/liquibase/ext/spanner/ICloudSpanner.java
// public interface ICloudSpanner extends Database {
// }


import liquibase.database.Database;
import liquibase.exception.ValidationErrors;
import liquibase.sql.Sql;
import liquibase.sql.UnparsedSql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.sqlgenerator.core.CreateTableGenerator;
import liquibase.statement.core.CreateTableStatement;
import liquibase.structure.DatabaseObject;
import liquibase.ext.spanner.ICloudSpanner;
    
    // Move the PRIMARY KEY statement from inside the table creation to outside.
    StringBuilder buffer = new StringBuilder(", PRIMARY KEY (");
    buffer.append(
            database.escapeColumnNameList(
                    String.join(", ", statement.getPrimaryKeyConstraint().getColumns())));
    buffer.append(")");

    String pk = buffer.toString();
    String sql = res[0].toSql();
    sql = sql.replace(pk, "");
    // Append PRIMARY KEY (without the leading ,)
    sql = sql + pk.substring(1);

    return new Sql[]{
            new UnparsedSql(
                    sql,
                    res[0]
                            .getAffectedDatabaseObjects()
                            .toArray(new DatabaseObject[res[0].getAffectedDatabaseObjects().size()]))
    };
  }

  @Override
  public int getPriority() {
    return PRIORITY_DATABASE;
  }

  @Override
  public boolean supports(CreateTableStatement statement, Database database) {
// Path: src/main/java/liquibase/ext/spanner/ICloudSpanner.java
// public interface ICloudSpanner extends Database {
// }


// Path: src/main/java/liquibase/ext/spanner/sqlgenerator/CreateTableGeneratorSpanner.java
import liquibase.database.Database;
import liquibase.exception.ValidationErrors;
import liquibase.sql.Sql;
import liquibase.sql.UnparsedSql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.sqlgenerator.core.CreateTableGenerator;
import liquibase.statement.core.CreateTableStatement;
import liquibase.structure.DatabaseObject;
import liquibase.ext.spanner.ICloudSpanner;

    
    // Move the PRIMARY KEY statement from inside the table creation to outside.
    StringBuilder buffer = new StringBuilder(", PRIMARY KEY (");
    buffer.append(
            database.escapeColumnNameList(
                    String.join(", ", statement.getPrimaryKeyConstraint().getColumns())));
    buffer.append(")");

    String pk = buffer.toString();
    String sql = res[0].toSql();
    sql = sql.replace(pk, "");
    // Append PRIMARY KEY (without the leading ,)
    sql = sql + pk.substring(1);

    return new Sql[]{
            new UnparsedSql(
                    sql,
                    res[0]
                            .getAffectedDatabaseObjects()
                            .toArray(new DatabaseObject[res[0].getAffectedDatabaseObjects().size()]))
    };
  }

  @Override
  public int getPriority() {
    return PRIORITY_DATABASE;
  }

  @Override
  public boolean supports(CreateTableStatement statement, Database database) {
    return (database instanceof ICloudSpanner);