-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Allow to manually sepecify column as Primary column option #244
Comments
can you share what the final API will looks like? |
Primary problem is not that much about being able to define BigID or ID columns (that ar BIGSERIAL or SERIAL in postgresql) and set them not being primary key. For example with my proposed API you can define something like: This would be needed to define partitioned table in PostgreSQL: schema.CreateTable("audit", func(t *rel.Table) {
t.BigID("id", rel.Primary(false))
t.DateTime("timestamp", rel.Required(true))
// other fields
t.PrimaryKeys([]string{"id", "timestamp"})
t.Options = `PARTITION BY RANGE ("timestamp")`
}) or you could define other type column as primary with alt syntax: schema.CreateTable("client", func(t *rel.Table) {
t.String("id", rel.Primary(true), rel.Limit(64))
// other fields
}) that would be equivalent to using: schema.CreateTable("client", func(t *rel.Table) {
t.String("id", rel.Limit(64))
// other fields
t.PrimaryKey("id")
}) |
as enhancements of above case I'm thinking to implicitly set Primary to false on column if schema.CreateTable("audit", func(t *rel.Table) {
t.BigID("id") // no need to specify Primary(false), will automatically set by `t.PrimaryKeys`
t.DateTime("timestamp", rel.Required(true))
// other fields
t.PrimaryKeys([]string{"id", "timestamp"})
t.Options = `PARTITION BY RANGE ("timestamp")`
}) what do you think? |
@lafriks can you update above prs? |
updated, can be merged, closing issue :) |
Currently there is no way to create BigID or ID column and not specifying it as primary key (it will always be created as primary key) but there are cases where you need to combine id and additional column as primary key - this is needed for partitioned tables in PostgreSQL
The text was updated successfully, but these errors were encountered: