fix: issues

This commit is contained in:
Rogee
2024-12-05 11:32:00 +08:00
parent 9ddd3f61ec
commit c6313f234b
17 changed files with 206 additions and 396 deletions

View File

@@ -2,6 +2,5 @@ ignores: [] # ignore tables
types:
users: # table name
oauth: backend/pkg/pg.UserOAuth
media_resources: # table name
type: backend/pkg/pg.MediaType
medias:
resources: backend/pkg/pg.MediaResources

View File

@@ -71,10 +71,11 @@ CREATE TABLE
uuid uuid NOT NULL,
tenant_id INT8 NOT NULL,
title VARCHAR(198) NOT NULL,
description VARCHAR(198) NOT NULL,
price INT8 NOT NULL,
description VARCHAR(198) NOT NULL default '',
price INT8 NOT NULL default 0,
discount INT8 NOT NULL default 100,
publish BOOL NOT NULL,
publish BOOL NOT NULL default false,
resources jsonb default '{}'::jsonb,
created_at timestamp NOT NULL default now(),
updated_at timestamp NOT NULL default now()
);
@@ -83,20 +84,6 @@ CREATE INDEX idx_medias_tenant_id ON medias (tenant_id);
CREATE INDEX idx_medias_title ON medias (title);
CREATE TABLE
media_resources (
id SERIAL8 PRIMARY KEY,
media_id INT8 NOT NULL,
type VARCHAR(128) NOT NULL,
source text NOT NULL default '',
size INT8 NOT NULL,
publish BOOL NOT NULL,
created_at timestamp NOT NULL default now(),
updated_at timestamp NOT NULL default now()
);
CREATE INDEX idx_media_resources_media_id ON media_resources (media_id);
CREATE TABLE user_medias (
id SERIAL8 PRIMARY KEY,
user_id INT8 NOT NULL,

View File

@@ -1,24 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"backend/pkg/pg"
"time"
)
type MediaResources struct {
ID int64 `sql:"primary_key" json:"id"`
MediaID int64 `json:"media_id"`
Type pg.MediaType `json:"type"`
Source string `json:"source"`
Size int64 `json:"size"`
Publish bool `json:"publish"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

View File

@@ -8,19 +8,21 @@
package model
import (
"backend/pkg/pg"
"github.com/google/uuid"
"time"
)
type Medias struct {
ID int64 `sql:"primary_key" json:"id"`
UUID uuid.UUID `json:"uuid"`
TenantID int64 `json:"tenant_id"`
Title string `json:"title"`
Description string `json:"description"`
Price int64 `json:"price"`
Discount int64 `json:"discount"`
Publish bool `json:"publish"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID int64 `sql:"primary_key" json:"id"`
UUID uuid.UUID `json:"uuid"`
TenantID int64 `json:"tenant_id"`
Title string `json:"title"`
Description string `json:"description"`
Price int64 `json:"price"`
Discount int64 `json:"discount"`
Publish bool `json:"publish"`
Resources pg.MediaResources `json:"resources"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

View File

@@ -1,96 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var MediaResources = newMediaResourcesTable("public", "media_resources", "")
type mediaResourcesTable struct {
postgres.Table
// Columns
ID postgres.ColumnInteger
MediaID postgres.ColumnInteger
Type postgres.ColumnString
Source postgres.ColumnString
Size postgres.ColumnInteger
Publish postgres.ColumnBool
CreatedAt postgres.ColumnTimestamp
UpdatedAt postgres.ColumnTimestamp
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type MediaResourcesTable struct {
mediaResourcesTable
EXCLUDED mediaResourcesTable
}
// AS creates new MediaResourcesTable with assigned alias
func (a MediaResourcesTable) AS(alias string) *MediaResourcesTable {
return newMediaResourcesTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new MediaResourcesTable with assigned schema name
func (a MediaResourcesTable) FromSchema(schemaName string) *MediaResourcesTable {
return newMediaResourcesTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new MediaResourcesTable with assigned table prefix
func (a MediaResourcesTable) WithPrefix(prefix string) *MediaResourcesTable {
return newMediaResourcesTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new MediaResourcesTable with assigned table suffix
func (a MediaResourcesTable) WithSuffix(suffix string) *MediaResourcesTable {
return newMediaResourcesTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newMediaResourcesTable(schemaName, tableName, alias string) *MediaResourcesTable {
return &MediaResourcesTable{
mediaResourcesTable: newMediaResourcesTableImpl(schemaName, tableName, alias),
EXCLUDED: newMediaResourcesTableImpl("", "excluded", ""),
}
}
func newMediaResourcesTableImpl(schemaName, tableName, alias string) mediaResourcesTable {
var (
IDColumn = postgres.IntegerColumn("id")
MediaIDColumn = postgres.IntegerColumn("media_id")
TypeColumn = postgres.StringColumn("type")
SourceColumn = postgres.StringColumn("source")
SizeColumn = postgres.IntegerColumn("size")
PublishColumn = postgres.BoolColumn("publish")
CreatedAtColumn = postgres.TimestampColumn("created_at")
UpdatedAtColumn = postgres.TimestampColumn("updated_at")
allColumns = postgres.ColumnList{IDColumn, MediaIDColumn, TypeColumn, SourceColumn, SizeColumn, PublishColumn, CreatedAtColumn, UpdatedAtColumn}
mutableColumns = postgres.ColumnList{MediaIDColumn, TypeColumn, SourceColumn, SizeColumn, PublishColumn, CreatedAtColumn, UpdatedAtColumn}
)
return mediaResourcesTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
MediaID: MediaIDColumn,
Type: TypeColumn,
Source: SourceColumn,
Size: SizeColumn,
Publish: PublishColumn,
CreatedAt: CreatedAtColumn,
UpdatedAt: UpdatedAtColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@@ -25,6 +25,7 @@ type mediasTable struct {
Price postgres.ColumnInteger
Discount postgres.ColumnInteger
Publish postgres.ColumnBool
Resources postgres.ColumnString
CreatedAt postgres.ColumnTimestamp
UpdatedAt postgres.ColumnTimestamp
@@ -75,10 +76,11 @@ func newMediasTableImpl(schemaName, tableName, alias string) mediasTable {
PriceColumn = postgres.IntegerColumn("price")
DiscountColumn = postgres.IntegerColumn("discount")
PublishColumn = postgres.BoolColumn("publish")
ResourcesColumn = postgres.StringColumn("resources")
CreatedAtColumn = postgres.TimestampColumn("created_at")
UpdatedAtColumn = postgres.TimestampColumn("updated_at")
allColumns = postgres.ColumnList{IDColumn, UUIDColumn, TenantIDColumn, TitleColumn, DescriptionColumn, PriceColumn, DiscountColumn, PublishColumn, CreatedAtColumn, UpdatedAtColumn}
mutableColumns = postgres.ColumnList{UUIDColumn, TenantIDColumn, TitleColumn, DescriptionColumn, PriceColumn, DiscountColumn, PublishColumn, CreatedAtColumn, UpdatedAtColumn}
allColumns = postgres.ColumnList{IDColumn, UUIDColumn, TenantIDColumn, TitleColumn, DescriptionColumn, PriceColumn, DiscountColumn, PublishColumn, ResourcesColumn, CreatedAtColumn, UpdatedAtColumn}
mutableColumns = postgres.ColumnList{UUIDColumn, TenantIDColumn, TitleColumn, DescriptionColumn, PriceColumn, DiscountColumn, PublishColumn, ResourcesColumn, CreatedAtColumn, UpdatedAtColumn}
)
return mediasTable{
@@ -93,6 +95,7 @@ func newMediasTableImpl(schemaName, tableName, alias string) mediasTable {
Price: PriceColumn,
Discount: DiscountColumn,
Publish: PublishColumn,
Resources: ResourcesColumn,
CreatedAt: CreatedAtColumn,
UpdatedAt: UpdatedAtColumn,

View File

@@ -10,7 +10,6 @@ package table
// UseSchema sets a new schema name for all generated table SQL builder types. It is recommended to invoke
// this method only once at the beginning of the program.
func UseSchema(schema string) {
MediaResources = MediaResources.FromSchema(schema)
Medias = Medias.FromSchema(schema)
Migrations = Migrations.FromSchema(schema)
TenantUserBalances = TenantUserBalances.FromSchema(schema)