Skip to content
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 usage of options on PK in postgreSQL #18

Merged
merged 5 commits into from
Aug 22, 2018

Conversation

JulienTant
Copy link
Contributor

@JulienTant JulienTant commented Aug 19, 2018

Fix #17

The following example doesn't work as I expected with PostgreSQL

create_table("table") {
    t.Column("id", "uuid", {"primary": true, "default_raw": "uuid_generate_v4()"})
}

I expected the column to be created as described but no options are taken into account when primary is set to true

This PR tries to fix the issue.

note: It may also work on sqlite and coackroach but I have absolutely no skill with them and don't wanna break anything... feel free to contribute to my fork, i can give you access to it so that you can push freely

@stanislas-m stanislas-m requested a review from a team August 19, 2018 17:49
@@ -23,19 +23,17 @@ func (p *Postgres) CreateTable(t fizz.Table) (string, error) {
for _, c := range t.Columns {
if c.Primary {
Copy link
Member

@stanislas-m stanislas-m Aug 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the primary check after adding the column itself? That's the way it's done with MySQL, so it should work the same way. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to avoid having a second if c.Primary bellow but if it's ok for you when i'm doing that!

@@ -11,7 +11,8 @@ var pgt = translators.NewPostgres()
func (p *PostgreSQLSuite) Test_Postgres_CreateTable() {
r := p.Require()
ddl := `CREATE TABLE "users" (
"id" SERIAL PRIMARY KEY,
PRIMARY KEY("id"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned previously, the MySQL driver have another output. We should have the same order (column def, then PRIMARY constraint) as in the MySQL driver.

@stanislas-m stanislas-m merged commit cfb4532 into gobuffalo:master Aug 22, 2018
@stanislas-m
Copy link
Member

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to define DEFAULT for PK with PostegreSQL
3 participants