-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
|
||
import static db.migration.CommonDbUtils.insertFile; | ||
|
||
public class V20240220_091__InsertTestFile extends BaseJavaMigration { |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
Change description
Does this PR introduce a breaking change? (check one with "x")