Skip to content

Commit

Permalink
Fix #1538: DB migration issue (MS SQL, possible Oracle) (#1543)
Browse files Browse the repository at this point in the history
* Fix #1538: DB migration issue (MS SQL, possible Oracle)

* Fix problem with MS SQL default value
* Make column non-null
  • Loading branch information
banterCZ authored Jun 3, 2024
1 parent 89b5222 commit 0a68528
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 2 deletions.
16 changes: 16 additions & 0 deletions docs-private/Developer-How-To-Start.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,27 @@ liquibase --changelog-file=./docs/db/changelog/changesets/powerauth-java-server/

To generate SQL script run this command.

#### Oracle

```shell
liquibase --changeLogFile=./docs/db/changelog/changesets/powerauth-java-server/db.changelog-module.xml --output-file=./docs/sql/oracle/generated-oracle-script.sql updateSQL --url=offline:oracle
```


#### MS SQL

```shell
liquibase --changeLogFile=./docs/db/changelog/changesets/powerauth-java-server/db.changelog-module.xml --output-file=./docs/sql/mssql/generated-mssql-script.sql updateSQL --url=offline:mssql
```


#### PostgreSQL

```shell
liquibase --changeLogFile=./docs/db/changelog/changesets/powerauth-java-server/db.changelog-module.xml --output-file=./docs/sql/postgresql/generated-postgresql-script.sql updateSQL --url=offline:postgres
```


## PowerAuth Admin Server


Expand Down
2 changes: 1 addition & 1 deletion docs/Database-Structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ CREATE TABLE pa_activation
device_info VARCHAR(255),
flags VARCHAR(255),
external_id VARCHAR(255),
protocol VARCHAR(32) DEFAULT 'powerauth',
protocol VARCHAR(32) DEFAULT 'powerauth' NOT NULL,
failed_attempts INTEGER NOT NULL,
max_failed_attempts INTEGER DEFAULT 5 NOT NULL,
server_private_key_base64 VARCHAR(255) NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@
<modifyDataType tableName="pa_activation" columnName="extras" newDataType="varchar(4000)"/>
</changeSet>

<!-- MS SQL default value issue https://github.com/liquibase/liquibase/issues/4644 -->
<changeSet id="4" logicalFilePath="powerauth-java-server/1.7.x/20240115-add-columns-fido2" author="Lubos Racansky">
<update tableName="pa_activation">
<column name="protocol" value="powerauth"/>
<where>protocol is null</where>
</update>
</changeSet>

<changeSet id="5" logicalFilePath="powerauth-java-server/1.7.x/20240530-protocol-not-null.xml" author="Lubos Racansky">
<comment>Make column pa_activation.protocol not-null.</comment>
<addNotNullConstraint tableName="pa_activation" columnName="protocol" columnDataType="varchar(32)" />
</changeSet>

</databaseChangeLog>
9 changes: 9 additions & 0 deletions docs/sql/mssql/migration_1.6.0_1.7.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ GO
ALTER TABLE pa_activation ALTER COLUMN extras varchar (4000);
GO

-- Changeset powerauth-java-server/1.7.x/20240115-add-columns-fido2::4::Lubos Racansky
UPDATE pa_activation SET protocol = 'powerauth' WHERE protocol is null;
GO

-- Changeset powerauth-java-server/1.7.x/20240530-protocol-not-null.xml::5::Lubos Racansky
-- Make column pa_activation.protocol not-null.
ALTER TABLE pa_activation ALTER COLUMN protocol varchar(32) NOT NULL;
GO

-- Changeset powerauth-java-server/1.7.x/20240212-application-config.xml::1::Roman Strobl
-- Create a new table pa_application_config
CREATE TABLE pa_application_config (id int NOT NULL, application_id int NOT NULL, config_key varchar(255) NOT NULL, config_values varchar (max), CONSTRAINT PK_PA_APPLICATION_CONFIG PRIMARY KEY (id), CONSTRAINT pa_app_config_app_fk FOREIGN KEY (application_id) REFERENCES pa_application(id));
Expand Down
7 changes: 7 additions & 0 deletions docs/sql/oracle/migration_1.6.0_1.7.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ ALTER TABLE pa_activation ADD protocol VARCHAR2(32) DEFAULT 'powerauth';
-- Changeset powerauth-java-server/1.7.x/20240115-add-columns-fido2::3::Roman Strobl
ALTER TABLE pa_activation MODIFY extras VARCHAR2(4000);

-- Changeset powerauth-java-server/1.7.x/20240115-add-columns-fido2::4::Lubos Racansky
UPDATE pa_activation SET protocol = 'powerauth' WHERE protocol is null;

-- Changeset powerauth-java-server/1.7.x/20240530-protocol-not-null.xml::5::Lubos Racansky
-- Make column pa_activation.protocol not-null.
ALTER TABLE pa_activation MODIFY protocol NOT NULL;

-- Changeset powerauth-java-server/1.7.x/20240212-application-config.xml::1::Roman Strobl
-- Create a new table pa_application_config
CREATE TABLE pa_application_config (id INTEGER NOT NULL, application_id INTEGER NOT NULL, config_key VARCHAR2(255) NOT NULL, config_values CLOB, CONSTRAINT PK_PA_APPLICATION_CONFIG PRIMARY KEY (id), CONSTRAINT pa_app_config_app_fk FOREIGN KEY (application_id) REFERENCES pa_application(id));
Expand Down
7 changes: 7 additions & 0 deletions docs/sql/postgresql/migration_1.6.0_1.7.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ ALTER TABLE pa_activation ADD protocol VARCHAR(32) DEFAULT 'powerauth';
-- Changeset powerauth-java-server/1.7.x/20240115-add-columns-fido2::3::Roman Strobl
ALTER TABLE pa_activation ALTER COLUMN extras TYPE VARCHAR(4000) USING (extras::VARCHAR(4000));

-- Changeset powerauth-java-server/1.7.x/20240115-add-columns-fido2::4::Lubos Racansky
UPDATE pa_activation SET protocol = 'powerauth' WHERE protocol is null;

-- Changeset powerauth-java-server/1.7.x/20240530-protocol-not-null.xml::5::Lubos Racansky
-- Make column pa_activation.protocol not-null.
ALTER TABLE pa_activation ALTER COLUMN protocol SET NOT NULL;

-- Changeset powerauth-java-server/1.7.x/20240212-application-config.xml::1::Roman Strobl
-- Create a new table pa_application_config
CREATE TABLE pa_application_config (id INTEGER NOT NULL, application_id INTEGER NOT NULL, config_key VARCHAR(255) NOT NULL, config_values TEXT, CONSTRAINT pa_application_config_pkey PRIMARY KEY (id), CONSTRAINT pa_app_config_app_fk FOREIGN KEY (application_id) REFERENCES pa_application(id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class ActivationRecordEntity implements Serializable {
@Column(name = "extras", columnDefinition = "CLOB")
private String extras;

@Column(name = "protocol")
@Column(name = "protocol", nullable = false, columnDefinition = "varchar(32) default 'powerauth'")
private String protocol;

@Column(name = "platform")
Expand Down

0 comments on commit 0a68528

Please sign in to comment.