3 ms·
The article seems to advocate generating code from a live connection to the production database. This seems very risky. Typically you don't want developers to
by skybrian 8y ago
The article seems to advocate generating code from a live connection to the production database.
This seems very risky. Typically you don't want developers to even have access to the production database most of the time, let alone make it a hard dependency to do a build. Development work should be done using temporary databases.
Also, database schema migrations need to be tested somewhere other than the prod database before going live. All the code changes needed (including to applications) should be written and tested before actually doing the migration.
But this approach would be reasonable with a bit of indirection: one developer (DBA?) makes a database schema change, resulting in a change to a schema file that's checked in (after testing), and code gets generated from the schema file. That way developers all have access to a history of the prod database schema, without access to the database itself.
(This is pretty close to how things are done using protocol buffers.)
- NovaX 8y agoI don't think anyone advocates for generating based on a production database connection. I can only tell you how I've used jOOQ, using the same general setup for 6 years despite job changes. I wrote the original Gradle plugins for jOOQ and Flyway, the latter being a migration tool. These were then contributed back and I use the official variants now. I write SQL migrations for H2, an in-memory db. This is used by the build tool to code generate prior to compilation. It is also used by unit tests, when the Postgres queries can be emulated (majority of the time). The Postgres migrations are written separately, with similar code but minor dialect differences. That might be less duplicated (but trivial) work if I used LiquiBase instead of Flyway. When the application starts the migrations are run. Someday I might drop H2 for a containerized Postgres, especially if they add in-memory support for faster testing. This would avoid some codegen differences, like jsonb or (soon to be released) enum support. The work setting things up wasn't too bad. It was more when I originally started, since I had to build part of the ecosystem. But repeating the process elsewhere has been straightforward. It definitely pays off and is a joy to use day to day.
- lukaseder 8y agoDefinitely no one runs jOOQ's code generation from the production database. Apart from the security concerns you've mentioned, that wouldn't make any sense, technically. When you implement a database increment, you will want to update your client logic immediately. That only happens on the development environment. Then you check in both the DB increment and the client logic change in version control for others to apply to their development databases, and ultimately to ship to production (with the generated code being pre-generated)