On Sunday, July 7, 2019 at 9:05:13 PM UTC-7, Shunsuke Tamiya wrote:
>
> Hi Jeremy, 
>
> I know how to insert values that are taken from another table when 
> migrations. 
>
> Sequel.migration do
>   up do
>     create_table(:slot, ignore_index_errors: false) do
>       String :uuid, size: 45, null: false
>       String :tenant_uuid, size: 45, null: false
>       column :slot, 'smallint unsigned', null: false
>       DateTime :created_at, default: Sequel.lit('CURRENT_TIMESTAMP'), null: 
> false
>       primary_key [:uuid, :tenant_uuid]
>     end
>     from(:slot).insert([:slot, :tenant_uuid], # This won't work because of no 
> uuid!
>       from(:tenants_users).select { [count(:tenant_uuid).as(:slot), 
> :tenant_uuid] }.group_by(:tenant_uuid)) # I am guessing there must be a way 
> to append uuid around here...
>   end
>     ...
> end
>
> However, what if I like to also add a new column, let's say uuid on slot 
> which doesn't exist on tenants_users. So I have to dynamically generate 
> uuids for slot table. The code above obviously not working due the reason. 
> I tried a bunch of ways but none of them not working so far.
>

You would have to use a database function to generate a UUID, and select 
that in the query.  Or switch to using import and generating a UUID 
manually for each row in Ruby.

Thanks,
Jeremy 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/ef0b264f-68b1-4c7c-87fe-26d911ba7952%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to