artanis
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Artanis] Foreign Key for Migrations


From: Jonathan Schmeling
Subject: Re: [Artanis] Foreign Key for Migrations
Date: Mon, 18 Mar 2019 01:31:46 +0000

So I was trying it out and I blew away my docker to repull the latest stuff for the fix.

When I first tried things out, I got the error:

web_1  | Loading conf/artanis.conf...done.
web_1  | User wants to use Database, initializing...
web_1  | connection pools are initilizing...DB pool init ok!
web_1  | Now the size of connection pool is 10.
web_1  | DB init done!
web_1  | Session with SIMPLE backend init done!
web_1  | Loading models...
web_1  | ;;; note: source file /myapp/ENTRY
web_1  | ;;;       newer than compiled /root/.cache/guile/ccache/2.2-LE-8-3.A/myapp/ENTRY.go
web_1  | ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
web_1  | ;;;       or pass the --no-auto-compile argument to disable.
web_1  | ;;; compiling /myapp/ENTRY
web_1  | ;;; compiled /root/.cache/guile/ccache/2.2-LE-8-3.A/myapp/ENTRY.go
web_1  | Backtrace:
web_1  |           12 (apply-smob/1 #<catch-closure 5568cab5d540>)
web_1  | In ice-9/boot-9.scm:
web_1  |     705:2 11 (call-with-prompt _ _ #<procedure default-prompt-handle…>)
web_1  | In ice-9/eval.scm:
web_1  |     619:8 10 (_ #(#(#<directory (guile-user) 5568cabf6140>)))
web_1  | In /usr/local/bin/art:
web_1  |     42:12  9 (_ _ _)
web_1  | In artanis/commands/work.scm:
web_1  |     135:8  8 (work . _)
web_1  | In artanis/artanis.scm:
web_1  |     320:2  7 (run #:host _ #:port _ #:debug _ #:use-db? _ #:db-proto …)
web_1  | In unknown file:
web_1  |            6 (run-hook #<hook 0 5568cadbd840 init-work>)
web_1  | In artanis/commands/work.scm:
web_1  |     119:2  5 (init-work)
web_1  |      73:2  4 (try-load-app)
web_1  | In srfi/srfi-1.scm:
web_1  |     640:9  3 (for-each #<procedure 5568cbb370a0 at artanis/mvc/mode…> …)
web_1  | In ice-9/boot-9.scm:
web_1  |    2312:4  2 (save-module-excursion #<procedure 5568cb6d8150 at ice-…>)
web_1  |   3822:12  1 (_)
web_1  | In app/models/PEOPLE.scm:
web_1  |       4:0  0 (_)
web_1  | 
web_1  | app/models/PEOPLE.scm:4:0: In procedure module-lookup: Unbound variable: PEOPLE

I figured it might be due to changes between what I'd used before and was using now so I deleted the old model I'd made and thought it'd get fixed by recreating it (later). So I deleted the file and tried starting up again (before recreating the model) and got this new error:

web_1  | Loading conf/artanis.conf...done.
web_1  | User wants to use Database, initializing...
web_1  | connection pools are initilizing...DB pool init ok!
web_1  | Now the size of connection pool is 10.
web_1  | DB init done!
web_1  | Session with SIMPLE backend init done!
web_1  | Loading models...
web_1  | Loading controllers...
web_1  | ;;; Stat of /myapp/app/controllers/#{}#.scm failed:
web_1  | ;;; In procedure stat: No such file or directory: "/myapp/app/controllers/#{}#.scm"
web_1  | Backtrace:
web_1  |            0 (primitive-load "/myapp/app/controllers/#{}#.scm")
web_1  | 
web_1  | ERROR: In procedure primitive-load:
web_1  | In procedure open-file: No such file or directory: "/myapp/app/controllers/#{}#.scm"

But I'm not certain what to make of this error, unfortunately.

Jonathan
On Sunday, March 17, 2019, 2:49:49 PM CDT, Nala Ginrut <address@hidden> wrote:



Hi Jonathan!
I've realized that there's bug in models after I fixed some bugs in
migration before.
Now I think it's fixed in a88c7e189a6a6273399e6e713be407ef55938f65

Please notice that you're forced to define the table in
define-artanis-model from now on, if you just leave it as
(define-artanis-model people) after drawing a model, then
art command will throw error.

Here's an example:
----------------code------------------
(create-artanis-model
people
(id auto (#:not-null #:primary-key))
(first_name char-field (#:maxlen 30 #:not-null))
(last_name char-field (#:maxlen 30 #:not-null)))
----------------end-------------------

And another notion is that the syntax is slightly different from the
mogration, in migration, you should use symbol explicitly:
-----------------code---------------------
(create-table
'people
'(id auto (#:not-null #:primary-key))
'(first_name char-field (#:maxlen 30 #:not-null))
'(last_name char-field (#:maxlen 30 #:not-null)))
-----------------end----------------------

But in Models, the list is quasiquote, so you can use unquote-sign, say
"," to escape the content if you like.

Please try it, and don't hasitate to report bugs. ;-)

Thanks!


Jonathan Schmeling writes:

> Thanks so much for the response! Ahhh; I did wonder if Artanis had anything had anything like that. That is really nice to work with.
>
> So I have a table named PEOPLE; so I ran art draw model PEOPLE and that reated a file named PEOPLE.scm which contains
>
> ;; Model PEOPLE definition of myapp
> ;; Please add your license header here.
> ;; This file is generated automatically by GNU Artanis.
> (create-artanis-model PEOPLE) ; DO NOT REMOVE THIS LINE!!!
>
> I then added to one of my controllers (use-modules (app models PEOPLE)) and running Artanis and visiting endpoints in that controller didn't throw any errors.
>
> So then I added a call similar to the one you had that uses ($PEOPLE …) in the controller; however, then I get the error In procedure module-lookup: Unbound variable: $PEOPLE when I visit the endpoint that uses the function call.
>
> Did I miss something?
>
> Jonathan
> On Saturday, March 16, 2019, 3:31:19 PM CDT, Nala Ginrut <address@hidden> wrote:
>
>
>
> Hi Jonathan!
> Sorry it's my mistake to neglect this part in the doc.
> You don't have to take care of the DB connection management by
> yourself. You may just use `art draw model person' to create the named
> mapping to the "person" table, and there's an exported relational
> mapping object named "$person", you may import (app models person) in
> other controller to use it. It's based on FPRM, but the table name has
> already been wrapped into the closure:
> https://www.gnu.org/software/artanis/manual/manual.html#orgeff2a47
>
> And maybe read its implementation is clearer to you:
> https://gitlab.com/NalaGinrut/artanis/blob/master/artanis/mvc/model.scm#L226
>
> The usage should look like this:
>
> ($person 'set #:name "nala" #:age 100)
>
> BTW, please don't forget to config your DB in conf/artanis.conf first.
>
> Best regards.
>
>
> Jonathan Schmeling writes:
>
>> Gotcha. That makes a lot of sense. Thanks a ton for explaining!
>>
>> Database related, is there a way to query the database from one of the controller -define methods (like (article-define show …) in the online documentation)? Using the function map-table-from-DB causes an error and attaching #:conn #t, like with the get function, also causes an error. Doing something like (:conn rc "SELECT * FROM PEOPLE") seems to work (or, at least, not throw an error) but I'm not sure what gets returned. The doc. says the returned value is described at https://www.gnu.org/software/artanis/manual/manual.html#org8ba121f but that section says "TODO".
>> As always, any help is always super appreciated!
>>
>> Jonathan
>>
>> On 2/17/19 12:19 PM, Nala Ginrut wrote:
>>
>>
>> Hi Jonathan!
>> I'm glad you asked this question.
>> The answer is actually written in the fprm.scm code comments that the
>> relational mapping in Artanis is not going to provide database level
>> foreign keys. The solution is to provide higher-abstract-level table
>> operations as a replacement to save users to time to handle by
>> themselves.
>>
>> The pros and cons of foreign keys are discussed a lot in the
>> internet. The modern ORM may choose to drop foreign keys and provide
>> higher layer for it.
>>
>>
>> Unfortunately, this feature has not been implemented yet because of my time schedule.
>>
>> Of course, this issue is still open, the original plan is more
>> ambitious. I think it's the time to add more features to the relational
>> mapping framework.
>> Welcome to discuss if you like.
>>
>> Best regards.
>>
>> Jonathan Schmeling writes:
>>
>>
>>
>> I'm not sure if it's been asked before but I couldn't find any mention
>> in the doc. – is it feasible to define foreign keys for the create-table
>> function? I want to reference another table's primary keys from a
>> particular table, to link them.
>>
>> Jonathan


--
GNU Powered it
GPL Protected it
GOD Blessed it
HFG - NalaGinrut
Fingerprint F53B 4C56 95B5 E4D5 6093 4324 8469 6772 846A 0058

reply via email to

[Prev in Thread] Current Thread [Next in Thread]