Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is gobuffalo able to generate my tables automatically?

I have this structure:

type User struct {
    ID        int
    CreatedAt int
    UpdatedAt int

    DeviceUniqueIdentifier string

    Sessions []Session `has_many:"sessions"`
}

I have no idea how to export this in fizz, so I did so:

buffalo pop generate model User

To my surprise, it actually generated a User and put a table in the database, but neither the table nor the structure are as expected.

Here is the new User struct:

...
type User struct {
    ID        uuid.UUID `json:"id" db:"id"`
    CreatedAt time.Time `json:"created_at" db:"created_at"`
    UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
...

Is there any way to generate passing some fields? Or is there a way to convert the structure to a table automatically?

like image 202
Ícaro Lima Avatar asked Jan 27 '26 21:01

Ícaro Lima


1 Answers

There's a way to generate a model passing some fields:

buffalo pop generate model User id:int device_unique_identifier

You have to add your columns definition after the name of the model. The column syntax allows you to give the column type (by default it's considered as a string).

You'll have to add your has_many relation by hand though, relations are not yet supported by the generator.

like image 57
Stanislas Michalak Avatar answered Jan 30 '26 11:01

Stanislas Michalak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!