feat: update
This commit is contained in:
@@ -75,7 +75,7 @@ func (up *uploads) PostUploadedAction(ctx fiber.Ctx, body *PostUploadedForm) err
|
||||
Hash: body.Md5,
|
||||
Path: filepath.Join(UPLOAD_PATH, body.Md5+filepath.Ext(body.OriginalName)),
|
||||
}
|
||||
if err := model.MediasModel().Create(ctx.Context(), m); err != nil {
|
||||
if err := m.Create(ctx.Context()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -89,12 +89,11 @@ func (w *VideoExtractHeadImageWorker) Work(ctx context.Context, job *Job[VideoEx
|
||||
|
||||
// create a new media record for the image
|
||||
imageMedia := &model.Medias{
|
||||
CreatedAt: time.Now(),
|
||||
Name: name,
|
||||
MimeType: "image/jpeg",
|
||||
Size: fileSize,
|
||||
Path: w.oss.GetSavePath(filename),
|
||||
Hash: fileMd5,
|
||||
Name: name,
|
||||
MimeType: "image/jpeg",
|
||||
Size: fileSize,
|
||||
Path: w.oss.GetSavePath(filename),
|
||||
Hash: fileMd5,
|
||||
Metas: fields.ToJson(fields.MediaMetas{
|
||||
ParentHash: media.Hash,
|
||||
}),
|
||||
@@ -110,7 +109,7 @@ func (w *VideoExtractHeadImageWorker) Work(ctx context.Context, job *Job[VideoEx
|
||||
log.Errorf("Error removing original file: %v", err)
|
||||
}
|
||||
|
||||
if err := model.MediasModel().Create(ctx, imageMedia); err != nil {
|
||||
if err := imageMedia.Create(ctx); err != nil {
|
||||
log.Errorf("Error creating media record: %v", err)
|
||||
return errors.Wrap(err, "failed to create media record")
|
||||
}
|
||||
|
||||
@@ -91,12 +91,11 @@ func (w *VideoStoreShortWorker) Work(ctx context.Context, job *Job[VideoStoreSho
|
||||
|
||||
// save to db and relate to master
|
||||
mediaModel := &model.Medias{
|
||||
CreatedAt: time.Now(),
|
||||
Name: "[试听]" + media.Name,
|
||||
MimeType: media.MimeType,
|
||||
Size: fileSize,
|
||||
Path: filePath,
|
||||
Hash: fileMd5,
|
||||
Name: "[试听] " + media.Name,
|
||||
MimeType: media.MimeType,
|
||||
Size: fileSize,
|
||||
Path: filePath,
|
||||
Hash: fileMd5,
|
||||
Metas: fields.ToJson(fields.MediaMetas{
|
||||
ParentHash: media.Hash,
|
||||
Short: true,
|
||||
@@ -112,7 +111,7 @@ func (w *VideoStoreShortWorker) Work(ctx context.Context, job *Job[VideoStoreSho
|
||||
}
|
||||
|
||||
log.Infof("pending create media record %s", job.Args.FilePath)
|
||||
if err := model.MediasModel().Create(ctx, mediaModel); err != nil {
|
||||
if err := mediaModel.Create(ctx); err != nil {
|
||||
log.Errorf("Error saving media record: %v data: %+v", err, mediaModel)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -97,12 +97,12 @@ func (m *Medias) BatchCreate(ctx context.Context, models []*Medias) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Medias) Create(ctx context.Context, medias *Medias) error {
|
||||
medias.CreatedAt = time.Now()
|
||||
stmt := table.Medias.INSERT(table.Medias.MutableColumns).MODEL(medias).RETURNING(table.Medias.AllColumns)
|
||||
func (m *Medias) Create(ctx context.Context) error {
|
||||
m.CreatedAt = time.Now()
|
||||
stmt := table.Medias.INSERT(table.Medias.MutableColumns).MODEL(m).RETURNING(table.Medias.AllColumns)
|
||||
m.log().Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, medias); err != nil {
|
||||
if err := stmt.QueryContext(ctx, db, m); err != nil {
|
||||
m.log().Errorf("error creating media item: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ func (s *MediasTestSuite) Test_Create() {
|
||||
Path: "path/to/media.pdf",
|
||||
}
|
||||
|
||||
err := MediasModel().Create(context.Background(), model)
|
||||
err := model.Create(context.Background())
|
||||
Convey("Create should not return an error", func() {
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
@@ -165,7 +165,7 @@ func (s *MediasTestSuite) Test_Page() {
|
||||
Path: "path/to/media.pdf",
|
||||
}
|
||||
|
||||
err := MediasModel().Create(context.Background(), model)
|
||||
err := model.Create(context.Background())
|
||||
So(err, ShouldBeNil)
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ func (s *MediasTestSuite) Test_CreateGetID() {
|
||||
Path: "path/to/media.pdf",
|
||||
}
|
||||
|
||||
err := MediasModel().Create(context.Background(), model)
|
||||
err := model.Create(context.Background())
|
||||
So(err, ShouldBeNil)
|
||||
So(model.ID, ShouldNotBeEmpty)
|
||||
|
||||
|
||||
@@ -1,19 +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 (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Migrations struct {
|
||||
ID int32 `sql:"primary_key" json:"id"`
|
||||
VersionID int64 `json:"version_id"`
|
||||
IsApplied bool `json:"is_applied"`
|
||||
Tstamp time.Time `json:"tstamp"`
|
||||
}
|
||||
@@ -1,84 +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 Migrations = newMigrationsTable("public", "migrations", "")
|
||||
|
||||
type migrationsTable struct {
|
||||
postgres.Table
|
||||
|
||||
// Columns
|
||||
ID postgres.ColumnInteger
|
||||
VersionID postgres.ColumnInteger
|
||||
IsApplied postgres.ColumnBool
|
||||
Tstamp postgres.ColumnTimestamp
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type MigrationsTable struct {
|
||||
migrationsTable
|
||||
|
||||
EXCLUDED migrationsTable
|
||||
}
|
||||
|
||||
// AS creates new MigrationsTable with assigned alias
|
||||
func (a MigrationsTable) AS(alias string) *MigrationsTable {
|
||||
return newMigrationsTable(a.SchemaName(), a.TableName(), alias)
|
||||
}
|
||||
|
||||
// Schema creates new MigrationsTable with assigned schema name
|
||||
func (a MigrationsTable) FromSchema(schemaName string) *MigrationsTable {
|
||||
return newMigrationsTable(schemaName, a.TableName(), a.Alias())
|
||||
}
|
||||
|
||||
// WithPrefix creates new MigrationsTable with assigned table prefix
|
||||
func (a MigrationsTable) WithPrefix(prefix string) *MigrationsTable {
|
||||
return newMigrationsTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||
}
|
||||
|
||||
// WithSuffix creates new MigrationsTable with assigned table suffix
|
||||
func (a MigrationsTable) WithSuffix(suffix string) *MigrationsTable {
|
||||
return newMigrationsTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||
}
|
||||
|
||||
func newMigrationsTable(schemaName, tableName, alias string) *MigrationsTable {
|
||||
return &MigrationsTable{
|
||||
migrationsTable: newMigrationsTableImpl(schemaName, tableName, alias),
|
||||
EXCLUDED: newMigrationsTableImpl("", "excluded", ""),
|
||||
}
|
||||
}
|
||||
|
||||
func newMigrationsTableImpl(schemaName, tableName, alias string) migrationsTable {
|
||||
var (
|
||||
IDColumn = postgres.IntegerColumn("id")
|
||||
VersionIDColumn = postgres.IntegerColumn("version_id")
|
||||
IsAppliedColumn = postgres.BoolColumn("is_applied")
|
||||
TstampColumn = postgres.TimestampColumn("tstamp")
|
||||
allColumns = postgres.ColumnList{IDColumn, VersionIDColumn, IsAppliedColumn, TstampColumn}
|
||||
mutableColumns = postgres.ColumnList{VersionIDColumn, IsAppliedColumn, TstampColumn}
|
||||
)
|
||||
|
||||
return migrationsTable{
|
||||
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||
|
||||
//Columns
|
||||
ID: IDColumn,
|
||||
VersionID: VersionIDColumn,
|
||||
IsApplied: IsAppliedColumn,
|
||||
Tstamp: TstampColumn,
|
||||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ package table
|
||||
// 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)
|
||||
UserPosts = UserPosts.FromSchema(schema)
|
||||
|
||||
@@ -6,6 +6,7 @@ ignores:
|
||||
- river_client_queue
|
||||
- river_job_state
|
||||
- river_queue
|
||||
- migrations
|
||||
model:
|
||||
- migrations
|
||||
- user_posts
|
||||
|
||||
Reference in New Issue
Block a user