feat: add storage and media table
This commit is contained in:
5
backend/database/fields/storage.go
Normal file
5
backend/database/fields/storage.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package fields
|
||||
|
||||
// swagger:enum UserStatus
|
||||
// ENUM( Local ,AliOSS, S3, MinIO)
|
||||
type StorageType int16
|
||||
@@ -0,0 +1,19 @@
|
||||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
-- create storages table
|
||||
CREATE TABLE storages (
|
||||
id SERIAL8 PRIMARY KEY,
|
||||
created_at timestamp NOT NULL default now(),
|
||||
updated_at timestamp NOT NULL default now(),
|
||||
|
||||
is_default BOOLEAN NOT NULL default false,
|
||||
name VARCHAR(128) NOT NULL default '',
|
||||
type INT2 NOT NULL default 0,
|
||||
config JSONB NOT NULL default '{}'
|
||||
);
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP TABLE storages;
|
||||
-- +goose StatementEnd
|
||||
23
backend/database/migrations/20250110093636_create_medias.sql
Normal file
23
backend/database/migrations/20250110093636_create_medias.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
-- create medias table
|
||||
CREATE TABLE medias (
|
||||
id SERIAL8 PRIMARY KEY,
|
||||
created_at timestamp NOT NULL default now(),
|
||||
updated_at timestamp NOT NULL default now(),
|
||||
|
||||
user_id INT8 NOT NULL,
|
||||
post_id INT8 NOT NULL,
|
||||
storage_id INT8 NOT NULL,
|
||||
name VARCHAR(255) NOT NULL default '',
|
||||
uuid VARCHAR(128) NOT NULL,
|
||||
mime_type VARCHAR(128) NOT NULL default '',
|
||||
size INT8 NOT NULL default 0,
|
||||
path VARCHAR(255) NOT NULL default ''
|
||||
);
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP TABLE medias;
|
||||
-- +goose StatementEnd
|
||||
26
backend/database/models/qvyun_v2/public/model/medias.go
Normal file
26
backend/database/models/qvyun_v2/public/model/medias.go
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// 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 (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Medias struct {
|
||||
ID int64 `sql:"primary_key" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
UserID int64 `json:"user_id"`
|
||||
PostID int64 `json:"post_id"`
|
||||
StorageID int64 `json:"storage_id"`
|
||||
Name string `json:"name"`
|
||||
UUID string `json:"uuid"`
|
||||
MimeType string `json:"mime_type"`
|
||||
Size int64 `json:"size"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
22
backend/database/models/qvyun_v2/public/model/storages.go
Normal file
22
backend/database/models/qvyun_v2/public/model/storages.go
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// 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 (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Storages struct {
|
||||
ID int64 `sql:"primary_key" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
IsDefault bool `json:"is_default"`
|
||||
Name string `json:"name"`
|
||||
Type int16 `json:"type"`
|
||||
Config string `json:"config"`
|
||||
}
|
||||
105
backend/database/models/qvyun_v2/public/table/medias.go
Normal file
105
backend/database/models/qvyun_v2/public/table/medias.go
Normal file
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// 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 Medias = newMediasTable("public", "medias", "")
|
||||
|
||||
type mediasTable struct {
|
||||
postgres.Table
|
||||
|
||||
// Columns
|
||||
ID postgres.ColumnInteger
|
||||
CreatedAt postgres.ColumnTimestamp
|
||||
UpdatedAt postgres.ColumnTimestamp
|
||||
UserID postgres.ColumnInteger
|
||||
PostID postgres.ColumnInteger
|
||||
StorageID postgres.ColumnInteger
|
||||
Name postgres.ColumnString
|
||||
UUID postgres.ColumnString
|
||||
MimeType postgres.ColumnString
|
||||
Size postgres.ColumnInteger
|
||||
Path postgres.ColumnString
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type MediasTable struct {
|
||||
mediasTable
|
||||
|
||||
EXCLUDED mediasTable
|
||||
}
|
||||
|
||||
// AS creates new MediasTable with assigned alias
|
||||
func (a MediasTable) AS(alias string) *MediasTable {
|
||||
return newMediasTable(a.SchemaName(), a.TableName(), alias)
|
||||
}
|
||||
|
||||
// Schema creates new MediasTable with assigned schema name
|
||||
func (a MediasTable) FromSchema(schemaName string) *MediasTable {
|
||||
return newMediasTable(schemaName, a.TableName(), a.Alias())
|
||||
}
|
||||
|
||||
// WithPrefix creates new MediasTable with assigned table prefix
|
||||
func (a MediasTable) WithPrefix(prefix string) *MediasTable {
|
||||
return newMediasTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||
}
|
||||
|
||||
// WithSuffix creates new MediasTable with assigned table suffix
|
||||
func (a MediasTable) WithSuffix(suffix string) *MediasTable {
|
||||
return newMediasTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||
}
|
||||
|
||||
func newMediasTable(schemaName, tableName, alias string) *MediasTable {
|
||||
return &MediasTable{
|
||||
mediasTable: newMediasTableImpl(schemaName, tableName, alias),
|
||||
EXCLUDED: newMediasTableImpl("", "excluded", ""),
|
||||
}
|
||||
}
|
||||
|
||||
func newMediasTableImpl(schemaName, tableName, alias string) mediasTable {
|
||||
var (
|
||||
IDColumn = postgres.IntegerColumn("id")
|
||||
CreatedAtColumn = postgres.TimestampColumn("created_at")
|
||||
UpdatedAtColumn = postgres.TimestampColumn("updated_at")
|
||||
UserIDColumn = postgres.IntegerColumn("user_id")
|
||||
PostIDColumn = postgres.IntegerColumn("post_id")
|
||||
StorageIDColumn = postgres.IntegerColumn("storage_id")
|
||||
NameColumn = postgres.StringColumn("name")
|
||||
UUIDColumn = postgres.StringColumn("uuid")
|
||||
MimeTypeColumn = postgres.StringColumn("mime_type")
|
||||
SizeColumn = postgres.IntegerColumn("size")
|
||||
PathColumn = postgres.StringColumn("path")
|
||||
allColumns = postgres.ColumnList{IDColumn, CreatedAtColumn, UpdatedAtColumn, UserIDColumn, PostIDColumn, StorageIDColumn, NameColumn, UUIDColumn, MimeTypeColumn, SizeColumn, PathColumn}
|
||||
mutableColumns = postgres.ColumnList{CreatedAtColumn, UpdatedAtColumn, UserIDColumn, PostIDColumn, StorageIDColumn, NameColumn, UUIDColumn, MimeTypeColumn, SizeColumn, PathColumn}
|
||||
)
|
||||
|
||||
return mediasTable{
|
||||
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||
|
||||
//Columns
|
||||
ID: IDColumn,
|
||||
CreatedAt: CreatedAtColumn,
|
||||
UpdatedAt: UpdatedAtColumn,
|
||||
UserID: UserIDColumn,
|
||||
PostID: PostIDColumn,
|
||||
StorageID: StorageIDColumn,
|
||||
Name: NameColumn,
|
||||
UUID: UUIDColumn,
|
||||
MimeType: MimeTypeColumn,
|
||||
Size: SizeColumn,
|
||||
Path: PathColumn,
|
||||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
}
|
||||
}
|
||||
93
backend/database/models/qvyun_v2/public/table/storages.go
Normal file
93
backend/database/models/qvyun_v2/public/table/storages.go
Normal file
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// 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 Storages = newStoragesTable("public", "storages", "")
|
||||
|
||||
type storagesTable struct {
|
||||
postgres.Table
|
||||
|
||||
// Columns
|
||||
ID postgres.ColumnInteger
|
||||
CreatedAt postgres.ColumnTimestamp
|
||||
UpdatedAt postgres.ColumnTimestamp
|
||||
IsDefault postgres.ColumnBool
|
||||
Name postgres.ColumnString
|
||||
Type postgres.ColumnInteger
|
||||
Config postgres.ColumnString
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type StoragesTable struct {
|
||||
storagesTable
|
||||
|
||||
EXCLUDED storagesTable
|
||||
}
|
||||
|
||||
// AS creates new StoragesTable with assigned alias
|
||||
func (a StoragesTable) AS(alias string) *StoragesTable {
|
||||
return newStoragesTable(a.SchemaName(), a.TableName(), alias)
|
||||
}
|
||||
|
||||
// Schema creates new StoragesTable with assigned schema name
|
||||
func (a StoragesTable) FromSchema(schemaName string) *StoragesTable {
|
||||
return newStoragesTable(schemaName, a.TableName(), a.Alias())
|
||||
}
|
||||
|
||||
// WithPrefix creates new StoragesTable with assigned table prefix
|
||||
func (a StoragesTable) WithPrefix(prefix string) *StoragesTable {
|
||||
return newStoragesTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||
}
|
||||
|
||||
// WithSuffix creates new StoragesTable with assigned table suffix
|
||||
func (a StoragesTable) WithSuffix(suffix string) *StoragesTable {
|
||||
return newStoragesTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||
}
|
||||
|
||||
func newStoragesTable(schemaName, tableName, alias string) *StoragesTable {
|
||||
return &StoragesTable{
|
||||
storagesTable: newStoragesTableImpl(schemaName, tableName, alias),
|
||||
EXCLUDED: newStoragesTableImpl("", "excluded", ""),
|
||||
}
|
||||
}
|
||||
|
||||
func newStoragesTableImpl(schemaName, tableName, alias string) storagesTable {
|
||||
var (
|
||||
IDColumn = postgres.IntegerColumn("id")
|
||||
CreatedAtColumn = postgres.TimestampColumn("created_at")
|
||||
UpdatedAtColumn = postgres.TimestampColumn("updated_at")
|
||||
IsDefaultColumn = postgres.BoolColumn("is_default")
|
||||
NameColumn = postgres.StringColumn("name")
|
||||
TypeColumn = postgres.IntegerColumn("type")
|
||||
ConfigColumn = postgres.StringColumn("config")
|
||||
allColumns = postgres.ColumnList{IDColumn, CreatedAtColumn, UpdatedAtColumn, IsDefaultColumn, NameColumn, TypeColumn, ConfigColumn}
|
||||
mutableColumns = postgres.ColumnList{CreatedAtColumn, UpdatedAtColumn, IsDefaultColumn, NameColumn, TypeColumn, ConfigColumn}
|
||||
)
|
||||
|
||||
return storagesTable{
|
||||
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||
|
||||
//Columns
|
||||
ID: IDColumn,
|
||||
CreatedAt: CreatedAtColumn,
|
||||
UpdatedAt: UpdatedAtColumn,
|
||||
IsDefault: IsDefaultColumn,
|
||||
Name: NameColumn,
|
||||
Type: TypeColumn,
|
||||
Config: ConfigColumn,
|
||||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ 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) {
|
||||
Medias = Medias.FromSchema(schema)
|
||||
Migrations = Migrations.FromSchema(schema)
|
||||
Orders = Orders.FromSchema(schema)
|
||||
Posts = Posts.FromSchema(schema)
|
||||
@@ -18,6 +19,7 @@ func UseSchema(schema string) {
|
||||
RiverJob = RiverJob.FromSchema(schema)
|
||||
RiverLeader = RiverLeader.FromSchema(schema)
|
||||
RiverQueue = RiverQueue.FromSchema(schema)
|
||||
Storages = Storages.FromSchema(schema)
|
||||
TenantUserBalances = TenantUserBalances.FromSchema(schema)
|
||||
TenantUsers = TenantUsers.FromSchema(schema)
|
||||
Tenants = Tenants.FromSchema(schema)
|
||||
|
||||
Reference in New Issue
Block a user