chrisdel101
Trouble processing long string and DB migration (1st argument: the table identifier does not refer to an existing ETS table)
Back Story: I’m trying to add all the timezones to my DB as an enum. I already do this with smaller values (not timezone-related) and it works fine.
EX:
execute "create type admin_role as enum #{convert_to_parens_string(get_admin_all_roles()}")
# executes as
execute "create type employee_role_value as enum ('owner', 'developer', 'admin', 'editor', 'contributor', 'viewer')"
"
Problem: In this non-working case I’m doing the exact same thing but the string output is huge. See it here. Function looks like this and is not working in execute.
# i have
execute("create type time_zone as enum #{convert_to_parens_string(Tzdata.zone_list)}")
# should be, but fails with error
execute("create type time_zone as enum ('Africa/Abidjan', 'Africa/Accra',...")
What I’ve Tried: Just trying to simply print is an issue. I cannot even get the values to print w.o truncation and I believe truncation might be happening during DB exec. The print statement ends at the <> symbol below but the data itself does not end there. It should go all the way to the Z’s.
IO.inspect(convert_to_parens_string(Tzdata.zone_list), limit: :infinity)
"('Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', 'Africa/Algiers', 'Africa/Asmara', 'Africa/Asmera', 'Africa/Bamako', 'Africa/Bangui', 'Africa/Banjul', 'Africa/Bissau', 'Africa/Blantyre', 'Africa/Brazzaville', 'Africa/Bujumbura', 'Africa/Cairo', 'Africa/Casablanca', 'Africa/Ceuta', 'Africa/Conakry', 'Africa/Dakar', 'Africa/Dar_es_Salaam'
...
'America/Regina', 'America/Resolute', 'America/Rio_Branco', 'Americ" <> ... # this is invalid and would cause an error
The function convert_to_parens_string works as expected since when I do File.write it writes the full string with no truncation to a file. If I paste this huge string into my DB enum thing it works (full string is shown at link above).
Question 1: How can I truly print w.o truncation? In iex the return is truncated and as shown before, using inspect w/ the limit: infinity is still truncated. Why is infinity not working?
Edit: I found this https://stackoverflow.com/a/61962447/5972531
Question 2: Can I print from inside a migration file? All my attempts have failed. I found writing to file works, but still not with my long string. I just get an error.
defmodule AddTimezoneType do
use Ecto.Migration
def change do
File.write("output.txt", "Hello") # this works
File.write("output.txt", "#{convert_to_parens_string(Tzdata.zone_list)}") # this does not work
end
end
if it’s returning a truncated version this would cause the error but I don’t know why it would do this, or how even confirm it.
Lastly, this seems to have nothing to do with the issue but the error I get when trying to run migrations but keeps coming up:
* 1st argument: the table identifier does not refer to an existing ETS table
Most Liked
benwilson512
There are separate limit and printable_limit values. You also need to set printable_limit to have text shown without truncation.
Tangentially, I’m not sure that a database enum is the right tool to model timezones.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









