Q for folks using nilenso/honeysql-postgres: how many of you actually use alter-table
(and the undocumented rename-table
)? It looks like it doesn't currently let you have multiple altering clauses (e.g., alter table foo add column id int, drop column ident;
type stuff). Would a syntax allowing multiple clauses be appreciated?
I'm thinking of something like:
{:alter-table :foo :add-column [:id :int]} ; single clause case
(-> (alter-table :foo) (add-column :id :int)) ; single clause helper version
;; proposed:
{:alter-table [:foo {:add-column [:id :int]} {:drop-column :ident}]} ; multi-clause case
(alter-table :foo (add-column :id :int) (:drop-column :ident)) ; multi-clause helper version
Yes it would be nice to have!
I actually had to write my own to get it to work in Gungnir 😅 https://github.com/kwrooijen/gungnir/blob/ef0c9a25bb00792e27a6d07871bb82feb8aaf50d/src/clj/gungnir/extension/honeysql_postgres.clj#L46-L60
If Honeysql would get first class support for creating / altering tables etc. It would simplify it for my library and I'd get rid of an extra dependency 🙂
(I currently use this to implement my migration system)
@kevin.van.rooijen Thanks for the feedback -- I'm most of the way through integrating and testing the last few parts of the nilenso library this afternoon (`do update set` is giving me fits! 👀 ) but by Monday this should all be sorted out and documented (integrating all these clauses in a consistent manner has led to some divergence -- so I plan to write a full "differences" page in the documentation).
And another PG Q about that library: is anyone actually using create-extension
and/or drop-extension
? What on earth do those even mean?
I use it to enable uuids
I don't use honeysql for ddl, but create and drop extension are for enabling and disabling postgres extensions (https://www.postgresql.org/docs/current/external-extensions.html), which are basically plug-ins adding functionality to postgres. For example, PostGIS is a popular extension adding spatial and geographic data types.
Morning - whilst I don't use alter table/rename table clauses, perhaps in the name of completeness they should be included (if minimal work involved!)
Yeah, create and drop extensions are for installing extensions within schemas
for example "create extension postgis schema foo"
would install the postgis extension into schema foo
there are lots of extensions
The problem, perhaps, with alter table (including it's rename variant) is there are tonnes of options on how to alter/create the table. <https://www.postgresql.org/docs/13/sql-altertable.html>
Would it be too much effort?
The way I use those clauses (create schema, alter table etc...) is only in my migration scripts (I use flywaydb). Since i would expect these to run on application start.
@dharrigan Thanks for that feedback. I ended up implementing add/drop/modify/rename column and add/drop index. I may implement more if folks request it. I'll go ahead and implement create/drop extension then since nilenso does have it.
I also added rename table (that's in the nilenso library but not documented -- seems there are quite a few things implemented and not documented there, so at least they'll all get documented now in HoneySQL v2!)
I've finished off testing my application, works perfectly with minimal changes to support honeysql v2
Brilliant! Thank you!
Today I'm going to post over the nilenso test suite and adjust it to work with v2 to check I have everything implemented.
you're most welcome 🙂