Menu

1 / 5

Goravel models and migrations with Postgres

DEV Community: postgres·Krishan·9 days ago
#8vz7Umq5
#devtopostgresql#devto#dev#table#migration
Reading 0:00
15s threshold

Part 4 of the Goravel series . The original on DevChalk has the colour-matched code, the figures and the full diffs. Code for this part: krishankumar01/goravel-taskflow/tree/part-04 .

TaskFlow reads requests, but it has nowhere to keep anything yet. In this part we create the users table from the database design . We write a model, and Goravel writes the migration from it.

Start from the Reading Request Data code:

git clone https://github.com/krishankumar01/goravel-taskflow cd goravel-taskflow git checkout part-03 cp .env.example .env go run . artisan key:generate docker compose up -d

Enter fullscreen mode

Exit fullscreen mode

The model

A model is a Go struct that stands for one table. Create one for users:

$ go run . artisan make:model User SUCCESS Model created successfully

Enter fullscreen mode

Exit fullscreen mode

This creates app/models/user.go :

app/models/user.go

package models

import ( "github.com/goravel/framework/database/orm" )

type User struct { orm .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.