juliolinarez

juliolinarez

Are default timestamps not allowed to be null in the database layer?

I realized that Ash generates timestamps in the application, which is what I want. To be sure, I removed the default values for those fields in the database migration. However, now when I run mix ash_postgres.generate_migrations, it wants to add a default value back in the snapshot files.

How can I prevent this?

  attributes do
    attribute :id, :uuid do
      primary_key? true
      allow_nil? false
      default &UUIDv7.generate/0
    end

    attribute :title, :string do
      allow_nil? false
    end

    attribute :content, :string do
      allow_nil? false
    end

    create_timestamp :inserted_at
    update_timestamp :updated_at
  end

Is there a way to prevent that globally?

Thank for this amazing framework :grinning_face:

Im using: ash 3.5.33, ash_postgres: 2.6.14, phoenix:1.7.21

First Post!

ken-kost

ken-kost

Looking at the docs, you should be able to set the default of the timestamp attributes to nil. :thinking:
To have it global you would need to make your own dsl and use that. Or just use attribute.

Last Post!

zachdaniel

zachdaniel

Creator of Ash

Yeah ultimately it should be safe to have it in both places, and acts as a benefit for retaining application behavior even when data is inserted directly into the database.

Where Next?

Popular in Discussions Top

mbenatti
Following https://github.com/tbrand/which_is_the_fastest |> https://raw.githubusercontent.com/tbrand/which_is_the_fastest/master/imgs...
New
PragTob
Hey everyone, this has been brewing in my head some time and it came up again while reading Adopting Elixir. GenServers, supervisors et...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18584 126
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement