Open Danwhy opened 5 years ago
When creating a table, we can add the cid primary key to the columns to create, then forward the modified request on to the Postgres adapter.
But what do we want to do if the user has already specified a primary key in their creation table. Do we raise an error, or do we create a composite primary key, which is the default when multiple columns are marked as the pk?
Raising an error might be a good first step if a primary key is defined by the user. As you mention on the standup we can later on if necessary create a new primary key by combining the cid and the primary key created by the user.
The only thing left to do for this function is to add a unique index for cid when a table is created (see https://github.com/dwyl/alog/issues/45#issuecomment-465493545).
Not sure exactly the best way to go about that yet, need to look into it a bit more.
Part of #38
https://hexdocs.pm/ecto_sql/Ecto.Adapters.SQL.Connection.html#c:execute_ddl/1
This is the function we use to run migrations. The existing implementation of this has multiple function clauses, so it's likely that we can use some of them, and override others.
It's here that we can ensure certain columns are added to tables when they're created, as well as defining the cid as the primary key.