fix: posts
This commit is contained in:
19
database/migrations/20250322103119_create_users.sql
Normal file
19
database/migrations/20250322103119_create_users.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
CREATE TABLE users(
|
||||
id SERIAL8 PRIMARY KEY,
|
||||
created_at timestamp NOT NULL DEFAULT now(),
|
||||
updated_at timestamp NOT NULL DEFAULT now(),
|
||||
deleted_at timestamp,
|
||||
status int2 NOT NULL DEFAULT 0,
|
||||
open_id varchar(128) NOT NULL UNIQUE,
|
||||
username varchar(128) NOT NULL,
|
||||
avatar varchar(128)
|
||||
);
|
||||
|
||||
-- +goose StatementEnd
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP TABLE users;
|
||||
|
||||
-- +goose StatementEnd
|
||||
18
database/migrations/20250322103243_create_user_posts.sql
Normal file
18
database/migrations/20250322103243_create_user_posts.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
CREATE TABLE user_posts(
|
||||
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,
|
||||
price int8 NOT NULL
|
||||
);
|
||||
|
||||
-- +goose StatementEnd
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP TABLE user_posts;
|
||||
|
||||
-- +goose StatementEnd
|
||||
21
database/schemas/public/model/user_posts.go
Normal file
21
database/schemas/public/model/user_posts.go
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// 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 UserPosts 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"`
|
||||
Price int64 `json:"price"`
|
||||
}
|
||||
23
database/schemas/public/model/users.go
Normal file
23
database/schemas/public/model/users.go
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// 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 Users struct {
|
||||
ID int64 `sql:"primary_key" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt *time.Time `json:"deleted_at"`
|
||||
Status int16 `json:"status"`
|
||||
OpenID string `json:"open_id"`
|
||||
Username string `json:"username"`
|
||||
Avatar *string `json:"avatar"`
|
||||
}
|
||||
@@ -13,4 +13,6 @@ func UseSchema(schema string) {
|
||||
Medias = Medias.FromSchema(schema)
|
||||
Migrations = Migrations.FromSchema(schema)
|
||||
Posts = Posts.FromSchema(schema)
|
||||
UserPosts = UserPosts.FromSchema(schema)
|
||||
Users = Users.FromSchema(schema)
|
||||
}
|
||||
|
||||
90
database/schemas/public/table/user_posts.go
Normal file
90
database/schemas/public/table/user_posts.go
Normal file
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// 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 UserPosts = newUserPostsTable("public", "user_posts", "")
|
||||
|
||||
type userPostsTable struct {
|
||||
postgres.Table
|
||||
|
||||
// Columns
|
||||
ID postgres.ColumnInteger
|
||||
CreatedAt postgres.ColumnTimestamp
|
||||
UpdatedAt postgres.ColumnTimestamp
|
||||
UserID postgres.ColumnInteger
|
||||
PostID postgres.ColumnInteger
|
||||
Price postgres.ColumnInteger
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type UserPostsTable struct {
|
||||
userPostsTable
|
||||
|
||||
EXCLUDED userPostsTable
|
||||
}
|
||||
|
||||
// AS creates new UserPostsTable with assigned alias
|
||||
func (a UserPostsTable) AS(alias string) *UserPostsTable {
|
||||
return newUserPostsTable(a.SchemaName(), a.TableName(), alias)
|
||||
}
|
||||
|
||||
// Schema creates new UserPostsTable with assigned schema name
|
||||
func (a UserPostsTable) FromSchema(schemaName string) *UserPostsTable {
|
||||
return newUserPostsTable(schemaName, a.TableName(), a.Alias())
|
||||
}
|
||||
|
||||
// WithPrefix creates new UserPostsTable with assigned table prefix
|
||||
func (a UserPostsTable) WithPrefix(prefix string) *UserPostsTable {
|
||||
return newUserPostsTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||
}
|
||||
|
||||
// WithSuffix creates new UserPostsTable with assigned table suffix
|
||||
func (a UserPostsTable) WithSuffix(suffix string) *UserPostsTable {
|
||||
return newUserPostsTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||
}
|
||||
|
||||
func newUserPostsTable(schemaName, tableName, alias string) *UserPostsTable {
|
||||
return &UserPostsTable{
|
||||
userPostsTable: newUserPostsTableImpl(schemaName, tableName, alias),
|
||||
EXCLUDED: newUserPostsTableImpl("", "excluded", ""),
|
||||
}
|
||||
}
|
||||
|
||||
func newUserPostsTableImpl(schemaName, tableName, alias string) userPostsTable {
|
||||
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")
|
||||
PriceColumn = postgres.IntegerColumn("price")
|
||||
allColumns = postgres.ColumnList{IDColumn, CreatedAtColumn, UpdatedAtColumn, UserIDColumn, PostIDColumn, PriceColumn}
|
||||
mutableColumns = postgres.ColumnList{CreatedAtColumn, UpdatedAtColumn, UserIDColumn, PostIDColumn, PriceColumn}
|
||||
)
|
||||
|
||||
return userPostsTable{
|
||||
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||
|
||||
//Columns
|
||||
ID: IDColumn,
|
||||
CreatedAt: CreatedAtColumn,
|
||||
UpdatedAt: UpdatedAtColumn,
|
||||
UserID: UserIDColumn,
|
||||
PostID: PostIDColumn,
|
||||
Price: PriceColumn,
|
||||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
}
|
||||
}
|
||||
96
database/schemas/public/table/users.go
Normal file
96
database/schemas/public/table/users.go
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// 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 Users = newUsersTable("public", "users", "")
|
||||
|
||||
type usersTable struct {
|
||||
postgres.Table
|
||||
|
||||
// Columns
|
||||
ID postgres.ColumnInteger
|
||||
CreatedAt postgres.ColumnTimestamp
|
||||
UpdatedAt postgres.ColumnTimestamp
|
||||
DeletedAt postgres.ColumnTimestamp
|
||||
Status postgres.ColumnInteger
|
||||
OpenID postgres.ColumnString
|
||||
Username postgres.ColumnString
|
||||
Avatar postgres.ColumnString
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type UsersTable struct {
|
||||
usersTable
|
||||
|
||||
EXCLUDED usersTable
|
||||
}
|
||||
|
||||
// AS creates new UsersTable with assigned alias
|
||||
func (a UsersTable) AS(alias string) *UsersTable {
|
||||
return newUsersTable(a.SchemaName(), a.TableName(), alias)
|
||||
}
|
||||
|
||||
// Schema creates new UsersTable with assigned schema name
|
||||
func (a UsersTable) FromSchema(schemaName string) *UsersTable {
|
||||
return newUsersTable(schemaName, a.TableName(), a.Alias())
|
||||
}
|
||||
|
||||
// WithPrefix creates new UsersTable with assigned table prefix
|
||||
func (a UsersTable) WithPrefix(prefix string) *UsersTable {
|
||||
return newUsersTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||
}
|
||||
|
||||
// WithSuffix creates new UsersTable with assigned table suffix
|
||||
func (a UsersTable) WithSuffix(suffix string) *UsersTable {
|
||||
return newUsersTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||
}
|
||||
|
||||
func newUsersTable(schemaName, tableName, alias string) *UsersTable {
|
||||
return &UsersTable{
|
||||
usersTable: newUsersTableImpl(schemaName, tableName, alias),
|
||||
EXCLUDED: newUsersTableImpl("", "excluded", ""),
|
||||
}
|
||||
}
|
||||
|
||||
func newUsersTableImpl(schemaName, tableName, alias string) usersTable {
|
||||
var (
|
||||
IDColumn = postgres.IntegerColumn("id")
|
||||
CreatedAtColumn = postgres.TimestampColumn("created_at")
|
||||
UpdatedAtColumn = postgres.TimestampColumn("updated_at")
|
||||
DeletedAtColumn = postgres.TimestampColumn("deleted_at")
|
||||
StatusColumn = postgres.IntegerColumn("status")
|
||||
OpenIDColumn = postgres.StringColumn("open_id")
|
||||
UsernameColumn = postgres.StringColumn("username")
|
||||
AvatarColumn = postgres.StringColumn("avatar")
|
||||
allColumns = postgres.ColumnList{IDColumn, CreatedAtColumn, UpdatedAtColumn, DeletedAtColumn, StatusColumn, OpenIDColumn, UsernameColumn, AvatarColumn}
|
||||
mutableColumns = postgres.ColumnList{CreatedAtColumn, UpdatedAtColumn, DeletedAtColumn, StatusColumn, OpenIDColumn, UsernameColumn, AvatarColumn}
|
||||
)
|
||||
|
||||
return usersTable{
|
||||
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||
|
||||
//Columns
|
||||
ID: IDColumn,
|
||||
CreatedAt: CreatedAtColumn,
|
||||
UpdatedAt: UpdatedAtColumn,
|
||||
DeletedAt: DeletedAtColumn,
|
||||
Status: StatusColumn,
|
||||
OpenID: OpenIDColumn,
|
||||
Username: UsernameColumn,
|
||||
Avatar: AvatarColumn,
|
||||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ ignores:
|
||||
- river_queue
|
||||
model:
|
||||
- migrations
|
||||
- user_posts
|
||||
types:
|
||||
# users: # table name
|
||||
# meta: UserMeta
|
||||
|
||||
Reference in New Issue
Block a user