sezaru
I have a system that needs to bulk load a bunch of data from time to time.
One way to speed that load process is to delete some of the indexes for that table an then, after the load is done, re-create it.
I can do that manually via psql, but an Ash Resource already has all the information about the index, so I was wondering if there is some way for me to generate, at runtime, the same queries ash_postgres.generate_migrations generates for the resource indexes.
In other words, I want to generate create index ... and drop index ... queries for each index and identity I have in my resource so I can execute it at runtime using Repo.query
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
Thinking about this, I don’t see how you could really do what you want that way…we generate ecto migration code. You’d have to define an ecto migration module and run it. If thats on the table then you could use
upto remove everything anddownto add them backsezaru
Sorry, I only was able to come back to this today..
So, when I run the
AshPostgres.MigrationGenerator.get_operations_from_snapshotsI get the following error:Seems like the function expects the attribute
sourcefield to be a string but in this case is an atom, there are other fields that will have the same problem, maybe I need to run another intermediary function to correctly normalize the snapshot for that function?zachdaniel
Hmm…Yeah, try json encoding and decoding it first. You probably shouldn’t have to do that, it should be done for you by
take_snapshotsI think? Either way, I think that might do it.sezaru
Hey @zachdaniel , here is a quick update regarding this issue:
I created a small resource to make troubleshot easier:
When I run the
take_snapshotcode, I get:If I just run the rest of the code, I will get the error shown above, to make it work I needed to do the following changes:
attributesfield array since I don’t need it and it will break;repofield value from atom to string;identitiesfield, I changed thenamefield value from atom to string;identitiesfield, I changed thekeysfield values from atom to string;After these changes, my snapshot changed to the following one:
After these changes, the rest of the code works great:
So, the problem is that `AshPostgres.MigrationGenerator expects that some values are string and try to convert it to an atom, but in this case they are already an atom.
An easy solution for that is just to add the following function to
AshPostgres.MigrationGenerator:And replace all
String.to_atomcalls in that module to use that function.After doing that the original snapshot starts working great.
Would you accept an PR with that change?
zachdaniel
I’d accept that PR, yeah
sezaru
Here it is: feat: Make MigrationGenerator accept atoms by sezaru · Pull Request #201 · ash-project/ash_postgres · GitHub
One of the test failed, but I don’t think it has anything to do with the PR.
sezaru
Thanks @zachdaniel for merging the PR, now the snapshot code works as intended
I do have another question thought, one of the things I want to also include in my changes is disabling/enabling the primary key constraint.
Basically I want to generate something that will do the following:
What I tried to do was to find the primary key attribute and change it to false in the second snapshot:
this will correctly generate the up and down code to drop and recreate the primary key, but it will also add a
drop constraintfunction to both:Any idea why that
drop constraint("entities", "entities_pkey")shows in both up and down migrations?zachdaniel
sezaru
Here is a quick code snippet that will reproduce the issue in case you want to confirm if it is a bug or not:
zachdaniel
I’ve got an idea here. Its a bit complicated, but we do need to drop the primary key in cases where we are adding/removing an attribute to it, but I think the problem is that in the case of removing a primary key we shouldn’t drop it in the up.