-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A way to define Definition
divorced from initial schema
#151
Comments
Can you give an example of what you mean by hinder? I guess you're talking about the constraint schemas1 ~ Alter sch (Create tab ('Table (constraints :=> columns)) schema0) schemas0 in |
I mean that there isn't a way (at least I couldn't think of it) to describe the If the two tables are independent, then they will both come from an empty schema. cat a b -> cat a c -> cat a (b + c) Which is more akin to a special case of Furthermore, a table definition could depend on a different specific table being defined. |
You can use the DDL type families to be polymorphic in the initial schema. createUser
:: Has "public" db schema
=> Definition db (Alter "public" (Create "user" UserTable schema) db) |
I think providing something akin to this might be useful (of course not hard-coded to the "public" schema): type SchemumCreation (s :: Symbol) (table :: SchemumType) =
forall db schema.
Has "public" db schema =>
Definition db (Alter "public" (Create s table schema) db) |
I think that's less clear. It wouldn't be as obvious |
Related: I am getting I think what I have written might not be strict enough somehow. (I have a |
If you have a foreign key in your definition then the column(s) it references must be unique and not null. You should specify that your primary key in the other table is not null. |
type TasksTable =
'Table
( '[ "pk_task_payload" :=> PrimaryKey '["task", "payload"]
]
:=> '[ "task" ::: 'NoDef :=> 'NotNull (PG Text),
"payload" ::: 'NoDef :=> 'NotNull (PG (Jsonb Value)),
"start_time" ::: 'NoDef :=> 'NotNull (PG UTCTime),
"initial_start_time" ::: 'NoDef :=> 'NotNull (PG UTCTime)
]
)
createTasksTable ::
Has "public" db schema =>
Definition db (Alter "public" (Create "tasks" TasksTable schema) db)
createTasksTable =
createTable
#tasks
( notNullable text `as` #task
:* notNullable jsonb `as` #payload
:* notNullable timestampWithTimeZone `as` #start_time
:* notNullable timestampWithTimeZone `as` #initial_start_time
)
( primaryKey (#task :* #payload) `as` #pk_task_payload
) This gives me:
|
The exact same code works when it is placed in a constant of type Definition (Public '[]) (Public '[ "tasks" ::: TasksTable ]) |
interesting...clearly GHC's having trouble inferring |
Just decomposition. Having one multi-thousand line file with every table and view definition and migration doesn't feel like a terribly good practice and feels like it will hinder maintainability and composability. (Compared to every definition/migration defining its own dependancies and separated into module). For example define two executables with their own sets of tables, which overlap. Can't think of a good way except for copy-pasting. |
In an ideal scenario every function could explicitly specify which tables it relies on and not depend on the whole schema. |
You can still decompose monomorphically though. In my project I have modules like |
You mean explicitly defining some midpoint schema and splitting the definition along that schema? |
basically, yes. Although I don't do one for each table, but just introduce a new |
Not ideal, but seems reasonable. Thanks |
You can of course break apart that first one however you like. As for maintainability though, I never change the old |
Currently the types of definition functions like
createTable
constrain the resulting schema, rather than deriving it from the initial schema and the definition itself, which kind of hinders the ability to decompose a schema definition into independentDefinition
s.The text was updated successfully, but these errors were encountered: