Skip to content

Commit

Permalink
Only change the column of the table exists
Browse files Browse the repository at this point in the history
The CI build fails on the alter table SPRING_SESSION_ATTRIBUTES
as it does not exists prior to initialising spring session
  • Loading branch information
oharsta committed Jul 18, 2024
1 parent 72d4af6 commit 46192c2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ jobs:
mysql-version: '8.3'
- run: |
mysql -uroot -h127.0.0.1 -e \
"CREATE DATABASE access CHARACTER SET utf8mb4 \
"CREATE DATABASE invite CHARACTER SET utf8mb4 \
COLLATE utf8mb4_0900_ai_ci;"
- run: |
mysql -uroot -h127.0.0.1 -e \
"CREATE USER 'access'@'localhost' IDENTIFIED BY 'secret';";
"CREATE USER 'invite'@'localhost' IDENTIFIED BY 'secret';";
- run: |
mysql -uroot -h127.0.0.1 -e \
"GRANT ALL privileges ON access.* TO 'access'@'localhost';"
"GRANT ALL privileges ON invite.* TO 'invite'@'localhost';"
- name: Build with Maven
run: mvn clean install --file pom.xml
- name: Codecov
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ jobs:
- name: Prepare database
run: |
mysql -uroot -h127.0.0.1 -e \
"CREATE DATABASE access CHARACTER SET utf8mb4 \
"CREATE DATABASE invite CHARACTER SET utf8mb4 \
COLLATE utf8mb4_0900_ai_ci;"
mysql -uroot -h127.0.0.1 -e \
"CREATE USER 'access'@'localhost' IDENTIFIED BY 'secret';";
"CREATE USER 'invite'@'localhost' IDENTIFIED BY 'secret';";
mysql -uroot -h127.0.0.1 -e \
"GRANT ALL privileges ON access.* TO 'access'@'localhost';"
"GRANT ALL privileges ON invite.* TO 'invite'@'localhost';"
if: ${{ steps.changes.outputs.server == 'true' || github.event_name == 'workflow_dispatch' }}

- name: Generate openapi.json
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package db.mysql.migration;

import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SingleConnectionDataSource;

import java.util.concurrent.atomic.AtomicReference;

//Only change the column of the table exists, otherwise the CI build fails
public class V31_0__session_attributes_medium_blob extends BaseJavaMigration {

public void migrate(Context context) {
JdbcTemplate jdbcTemplate =
new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true));
jdbcTemplate.query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES " +
"WHERE TABLE_SCHEMA = 'invite' " +
"AND TABLE_NAME = 'SPRING_SESSION_ATTRIBUTES'", rs -> {
jdbcTemplate.update("ALTER TABLE SPRING_SESSION_ATTRIBUTES " +
"CHANGE COLUMN ATTRIBUTE_BYTES ATTRIBUTE_BYTES MEDIUMBLOB");
});
}
}

This file was deleted.

0 comments on commit 46192c2

Please sign in to comment.