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

PoC to demonstrate inserting files (as bytea) with Flyway #210

Closed
wants to merge 3 commits into from

Conversation

danlysiak
Copy link
Member

Change description

Does this PR introduce a breaking change? (check one with "x")

[ ] Yes
[ ] No


import static db.migration.CommonDbUtils.insertFile;

public class V20240220_091__InsertTestFile extends BaseJavaMigration {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same naming convention can and should be used as with the SQL files


@Override
public void migrate(Context context) throws IOException {
insertFile(context, "someFileName", "db/files/sample.pdf");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add as many files as we want for a single migration


public class CommonDbUtils {

public static void insertFile(Context context, String name, String file) throws IOException {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on needs of table that we're actually inserting to, name this method more appropriately and pass in relevant args


public static void insertFile(Context context, String name, String file) throws IOException {
JdbcTemplate jdbcTemplate = new JdbcTemplate(context.getConfiguration().getDataSource());
jdbcTemplate.update("INSERT INTO file_poc (name, value) VALUES ((?), (?))", name, readFileFromResources(file));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modify this generic query appropriately; we may want to either make it either more generic a query or have separate methods for different table inserts if there are different scenarios

@danlysiak danlysiak closed this Feb 28, 2024
@RustyHMCTS RustyHMCTS deleted the flyway-file-insert-poc branch April 26, 2024 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants