Perl 6 - the future is here, just unevenly distributed

IRC log for #askriba, 2017-08-24

| Channels | #askriba index | Today | | Search | Google Search | Plain-Text | summary

All times shown according to UTC.

Time Nick Message
04:04 dboehmer joined #askriba
08:16 Relequestual joined #askriba
10:56 Relequestual joined #askriba
11:23 ashimema hmm.. meant to post this here.. but ended up on #dbic instead
11:23 ashimema can someone point me to the right docs page for how to add a custom constraint into the resultsource so it gets deployed with deployment handler
11:23 ashimema pretty sure I've got a grasp on how to create my constraint from here: https://metacpan.org/pod/SQL::Translator::Schema::Constraint#type
11:23 ashimema "ashimema" at 217.168.150.38 pasted "xor constraint" (6 lines) at http://paste.scsys.co.uk/564941
11:24 ashimema that's the constraint I've come up with.. but yeah.. I've got myself confused with how there fit into the bigger picture
11:33 ribasushi several options are available, given it is expressible in SQLT
11:34 ashimema I 'think' I've just worked it out.. one moment and I'll paste what I've got.. would appreciate pointers if there's a 'better way' (or if I'm just plain wrong ;))
11:34 ribasushi you can use https://metacpan.org/pod/DBIx::Class::Schema#sqlt_deploy_hook
11:34 ribasushi example in https://metacpan.org/pod/distribution/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod#Adding-Indexes-And-Functions-To-Your-SQL
11:35 ribasushi basically this hands back the *sqlt* object back to you to add extra pieces to it during the deployment_statements() invocation
11:35 ribasushi ( you define the callback within the corresponding Result class )
11:35 ribasushi OR
11:36 ribasushi given you are using DH you can simply add plain SQL to be picked up in the sql-files as described here: https://metacpan.org/pod/DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator#DIRECTORY-LAYOUT
11:36 ashimema http://paste.scsys.co.uk/564942 is what I came up with..
11:36 * ribasushi looks...
11:37 ashimema brill.. so yeah.. I think my option is your first one..
11:37 ashimema I've used your second option before actually.. :)  To add triggers
11:37 ashimema not sure why I didn't think of it this time
11:37 ashimema thanks ribasushi
11:39 ribasushi ashimema: note that using deploy_callback preempts using deploy_hook ( a silly wart due to misdesigns )
11:40 ribasushi something to keep in mind in the future if you end up trying to use both and things don't work
11:40 * ribasushi makes a note to add this situation to the linter when things unblock...
11:40 * ashimema reads that again to try and make sense
11:40 ribasushi ashimema: the two methods basically differ by what the first argument to the coderef will be
11:41 ashimema I see
11:41 ribasushi and as such they do not combine well - specifying sqlt_deploy_callback means sqlt_deploy_hook will never execute
11:41 ribasushi I am pointing this out "for the future"
11:41 ribasushi what you did *now* will work
11:41 ashimema I did wonder why there was a 'default_deploy_hook' and a 'deploy_callback'.. I kinda expected them to have matching names.
11:42 ashimema one is at the schema level and the other is at the resultsource level too isn't it
11:42 * ashimema will just read the docs again rather than stealing more of riba's time
11:42 ashimema but thankyou
11:42 ribasushi it's not documented is the problem
11:43 * ribasushi lists the chain here for his own future ref:
11:46 ashimema hmm
11:46 ashimema that actually fires off: {UNKNOWN}: Can't locate object method "sqlt_deploy_callback" via package "Rebus::Schema::Result::Notification" at /home/rebus/rebus-list/script/../lib/Rebus/Schema/Result/Notification.pm line 128.
11:46 ribasushi when the SQLT parser runs through the DBIC schema it invokes each hook in turn here ( note $rsrc as $_[0] ):
11:46 ribasushi https://metacpan.org/source/RIBASUSHI/DBIx-Class-0.082840/lib/DBIx/Class/ResultSource.pm#L33
11:46 ribasushi this in turn jumps through:
11:46 ribasushi https://metacpan.org/source/RIBASUSHI/DBIx-Class-0.082840/lib/DBIx/Class/ResultSource.pm#L1001
11:46 ribasushi which defaults to
11:46 ashimema so i tihnk I'm better off switching it to a deploy_hook sub at this point anyway..
11:46 ribasushi https://metacpan.org/source/RIBASUSHI/DBIx-Class-0.082840/lib/DBIx/Class/ResultSource.pm#L33
11:46 ribasushi which jumps to
11:47 ribasushi https://metacpan.org/source/RIBASUSHI/DBIx-Class-0.082840/lib/DBIx/Class/ResultSource.pm#L989
11:47 ribasushi which ( if nothing in the chain has been overriden so far ) invokes the last bit, with a *different* $_[0]:
11:47 ribasushi https://metacpan.org/source/RIBASUSHI/DBIx-Class-0.082840/lib/DBIx/Class/ResultSource.pm#L994
11:47 ribasushi "easy" isn't it?
11:47 ribasushi ashimema: ^^ this is the chain of events, it is straightforward, just long
11:47 ashimema haha
11:47 ashimema think I cut your paste in half there.. sorry
11:48 ribasushi ashimema: if all is equal - I'd recommend using the last bit: sub sqlt_deploy_hook { my $sqlt_table_object = $_[1]; ... }
11:48 ribasushi within the result class in question
11:48 ashimema :)
11:48 ashimema thanks.. that's exactly what I think I just decided to do
11:48 ashimema historical that they both exist?  or is there a good reason to use callback still anymore?
11:49 ribasushi originally it was only the sqlt_deploy_hook method, which only gets $class ( as string) as $_[0], and thus does not have access to the current $schema-tree that is actually active
11:50 ribasushi so the callback system was put in place with all the indirection, to provide the actual $rsrc ( with access to actual $schema and $storage ), and to keep the original working was made by default to invoke sqlt_deploy_hook if nothing else is in the way
11:51 ashimema aha.. I see.. thanks
11:51 ashimema that last bit was just enough for me to have that light bulb moment :)
11:51 ashimema as ever, a pleasure ribasushi :)
11:52 ashimema seems to have added some noise to my db prepare: Exiting subroutine via next at /home/rebus/rebus-list/script/../local/lib/perl5/SQL/Translator/Producer/PostgreSQL.pm line 581.
11:52 ribasushi ashimema: note: for new code, starting off sqlt_deploy_callback is in fact more correct, but given you ran into problems means that there is some weird interaction with DH or something, so might as well use the long-form that seems to work in your case
11:53 ribasushi grrrr
11:53 ribasushi looking...
11:53 ashimema sorry
11:54 ribasushi nothing to be sorry about, the stack is shit, you just happen to run into it ;)
11:55 ashimema hmm.. not just noise.. i expected the for the deploy hook to get added into my 001-auto.sql.. it didn't :(
11:55 ribasushi this is an error in the code, the next() should have been a return()
11:55 ribasushi https://metacpan.org/source/ILMARI/SQL-Translator-0.11021/lib/SQL/Translator/Producer/PostgreSQL.pm#L581
11:55 ashimema hmm.. I have a feeling I've read something about that in the DH docs somewhere
11:56 ribasushi not fixed in the repo either it seems
11:56 ribasushi let me look a bit more...
11:56 ashimema thanks
11:56 ribasushi actually this very line is a hint
11:57 ribasushi the Pg producer expects fields (column names ) for *any* constraint that is not a check type
11:57 ribasushi otherwise it just doesn't produce a statement for this structure
11:57 ashimema ooh.. interesting
11:57 ribasushi http://paste.scsys.co.uk/564942 <--- you need to add type or something...
11:57 ribasushi but not sure how it will play out...
11:58 ribasushi all in all it seems you will have better luck bypassing SQLT: the producer needs work
11:58 ashimema I did wonder about type.. I couldn't find where to look for the enum that type accepts.. it ws unclear ;)
11:58 ashimema back to DH manually then
11:58 ribasushi wait...
11:58 ribasushi this *is* a check constraint in the end, right?
11:59 * ashimema wishes he could find where in the DH docs it talked about indexes or constraints or somthing getting nuked with upgrade if you didn't do something special.
11:59 ashimema yup
11:59 ashimema it is a check constraint
11:59 ribasushi so  type => "CHECK" should do it
11:59 ribasushi https://metacpan.org/source/SQL::Translator::Schema::Constants#L63 <--- what the code compares to
11:59 ashimema it's basically a 'Check that 1 and only 1 of these fields is not null'
12:00 ashimema thanks
12:00 ribasushi then https://metacpan.org/source/ILMARI/SQL-Translator-0.11021/lib/SQL/Translator/Producer/PostgreSQL.pm#L581 will satisfy, and hopefully the rest will output the right magic
12:01 ashimema that's the ticket :)
12:02 ashimema thanks again :)
12:03 * ashimema isn't sure how he could do without dbic these days..
12:05 ribasushi well afaik your other mojo project moved away from DBIC, so you are clearly managing :D
12:06 ashimema it didn't move that far yet..
12:06 ashimema it's a slow move.. currently it uses dbic for 98% and Mojo::Pg for the other 2% ;)
12:07 ashimema mostly I only use Mojo::Pg currently for the pg specific `notify` and `listen`.. basically using pg as a message broker
12:07 ashimema I'm even using dh to actually add the triggers that the listen is intercepting ;)
12:08 ribasushi nod
12:08 ashimema we just sold that project though.. they've only got me contracting on it for the new owners for another 6 months (likely they'll ask for another 6 I reckon)
12:09 ashimema I've learnt so much along the way with it.. my first proper adventure into dbic.. my first proper adventure into mojo, websockets and non-blocking style coding
12:10 ashimema poor people...  there's so much in there I cringe about now I look back
12:10 ashimema oh well
12:10 ribasushi always the case
14:32 karjala_ joined #askriba

| Channels | #askriba index | Today | | Search | Google Search | Plain-Text | summary