feat: add uuid for medias

This commit is contained in:
Rogee
2024-12-04 15:47:48 +08:00
parent 774f8644ab
commit 385c1b1e2f
5 changed files with 14 additions and 3 deletions

View File

@@ -68,6 +68,7 @@ CREATE INDEX idx_user_balance_histories_tenant_id ON user_balance_histories (ten
CREATE TABLE CREATE TABLE
medias ( medias (
id SERIAL8 PRIMARY KEY, id SERIAL8 PRIMARY KEY,
uuid uuid NOT NULL,
tenant_id INT8 NOT NULL, tenant_id INT8 NOT NULL,
title VARCHAR(198) NOT NULL, title VARCHAR(198) NOT NULL,
description VARCHAR(198) NOT NULL, description VARCHAR(198) NOT NULL,

View File

@@ -8,11 +8,13 @@
package model package model
import ( import (
"github.com/google/uuid"
"time" "time"
) )
type Medias struct { type Medias struct {
ID int64 `sql:"primary_key" json:"id"` ID int64 `sql:"primary_key" json:"id"`
UUID uuid.UUID `json:"uuid"`
TenantID int64 `json:"tenant_id"` TenantID int64 `json:"tenant_id"`
Title string `json:"title"` Title string `json:"title"`
Description string `json:"description"` Description string `json:"description"`

View File

@@ -18,6 +18,7 @@ type mediasTable struct {
// Columns // Columns
ID postgres.ColumnInteger ID postgres.ColumnInteger
UUID postgres.ColumnString
TenantID postgres.ColumnInteger TenantID postgres.ColumnInteger
Title postgres.ColumnString Title postgres.ColumnString
Description postgres.ColumnString Description postgres.ColumnString
@@ -67,6 +68,7 @@ func newMediasTable(schemaName, tableName, alias string) *MediasTable {
func newMediasTableImpl(schemaName, tableName, alias string) mediasTable { func newMediasTableImpl(schemaName, tableName, alias string) mediasTable {
var ( var (
IDColumn = postgres.IntegerColumn("id") IDColumn = postgres.IntegerColumn("id")
UUIDColumn = postgres.StringColumn("uuid")
TenantIDColumn = postgres.IntegerColumn("tenant_id") TenantIDColumn = postgres.IntegerColumn("tenant_id")
TitleColumn = postgres.StringColumn("title") TitleColumn = postgres.StringColumn("title")
DescriptionColumn = postgres.StringColumn("description") DescriptionColumn = postgres.StringColumn("description")
@@ -75,8 +77,8 @@ func newMediasTableImpl(schemaName, tableName, alias string) mediasTable {
PublishColumn = postgres.BoolColumn("publish") PublishColumn = postgres.BoolColumn("publish")
CreatedAtColumn = postgres.TimestampColumn("created_at") CreatedAtColumn = postgres.TimestampColumn("created_at")
UpdatedAtColumn = postgres.TimestampColumn("updated_at") UpdatedAtColumn = postgres.TimestampColumn("updated_at")
allColumns = postgres.ColumnList{IDColumn, TenantIDColumn, TitleColumn, DescriptionColumn, PriceColumn, DiscountColumn, PublishColumn, CreatedAtColumn, UpdatedAtColumn} allColumns = postgres.ColumnList{IDColumn, UUIDColumn, TenantIDColumn, TitleColumn, DescriptionColumn, PriceColumn, DiscountColumn, PublishColumn, CreatedAtColumn, UpdatedAtColumn}
mutableColumns = postgres.ColumnList{TenantIDColumn, TitleColumn, DescriptionColumn, PriceColumn, DiscountColumn, PublishColumn, CreatedAtColumn, UpdatedAtColumn} mutableColumns = postgres.ColumnList{UUIDColumn, TenantIDColumn, TitleColumn, DescriptionColumn, PriceColumn, DiscountColumn, PublishColumn, CreatedAtColumn, UpdatedAtColumn}
) )
return mediasTable{ return mediasTable{
@@ -84,6 +86,7 @@ func newMediasTableImpl(schemaName, tableName, alias string) mediasTable {
//Columns //Columns
ID: IDColumn, ID: IDColumn,
UUID: UUIDColumn,
TenantID: TenantIDColumn, TenantID: TenantIDColumn,
Title: TitleColumn, Title: TitleColumn,
Description: DescriptionColumn, Description: DescriptionColumn,

View File

@@ -9,6 +9,7 @@ require (
github.com/gofiber/fiber/v3 v3.0.0-beta.3 github.com/gofiber/fiber/v3 v3.0.0-beta.3
github.com/gofrs/uuid v4.4.0+incompatible github.com/gofrs/uuid v4.4.0+incompatible
github.com/golang-jwt/jwt/v4 v4.5.1 github.com/golang-jwt/jwt/v4 v4.5.1
github.com/google/uuid v1.6.0
github.com/imroc/req/v3 v3.48.0 github.com/imroc/req/v3 v3.48.0
github.com/jinzhu/copier v0.4.0 github.com/jinzhu/copier v0.4.0
github.com/juju/go4 v0.0.0-20160222163258-40d72ab9641a github.com/juju/go4 v0.0.0-20160222163258-40d72ab9641a
@@ -38,7 +39,6 @@ require (
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect
github.com/google/pprof v0.0.0-20240910150728-a0b0bb1d4134 // indirect github.com/google/pprof v0.0.0-20240910150728-a0b0bb1d4134 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect

View File

@@ -11,6 +11,7 @@ import (
"backend/pkg/pg" "backend/pkg/pg"
. "github.com/go-jet/jet/v2/postgres" . "github.com/go-jet/jet/v2/postgres"
"github.com/google/uuid"
"github.com/samber/lo" "github.com/samber/lo"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
) )
@@ -77,6 +78,7 @@ func TestService_List(t *testing.T) {
Convey("insert medias data", func() { Convey("insert medias data", func() {
items := []model.Medias{ items := []model.Medias{
{ {
UUID: uuid.New(),
TenantID: 1, TenantID: 1,
Title: "title1", Title: "title1",
Description: "hello", Description: "hello",
@@ -84,6 +86,7 @@ func TestService_List(t *testing.T) {
Publish: true, Publish: true,
}, },
{ {
UUID: uuid.New(),
TenantID: 1, TenantID: 1,
Title: "title2", Title: "title2",
Description: "hello", Description: "hello",
@@ -91,6 +94,7 @@ func TestService_List(t *testing.T) {
Publish: true, Publish: true,
}, },
{ {
UUID: uuid.New(),
TenantID: 1, TenantID: 1,
Title: "title3", Title: "title3",
Description: "hello", Description: "hello",
@@ -101,6 +105,7 @@ func TestService_List(t *testing.T) {
tbl := table.Medias tbl := table.Medias
stmt := tbl.INSERT( stmt := tbl.INSERT(
tbl.UUID,
tbl.TenantID, tbl.TenantID,
tbl.Title, tbl.Title,
tbl.Description, tbl.Description,