Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b774d2b3c9 | |||
| d124229308 | |||
| bf7a11076f | |||
| c7176fadf6 | |||
| bc4354bf7b | |||
| 00ab98072b | |||
| c39d82fafd | |||
| 4e0fc431e2 | |||
| 7384751d6b | |||
| 49952c62ef | |||
| 057ba22b18 | |||
| 35d41a46c0 | |||
| dbc34a8e0d | |||
| 912c7b80a3 | |||
| 900770ff36 | |||
| 7062cb630e | |||
| 436f164ab9 | |||
| d9ca913620 | |||
| 153020b9c7 | |||
| effcd2c073 | |||
| 78885b3656 | |||
| 828d611f4d | |||
| 82bd446a85 | |||
| 24075e5a76 | |||
| 27184bf17a | |||
| ec17dfb0ce | |||
| 6e3328ca83 | |||
| 164ea9a6c8 | |||
| 761babfa1a | |||
| 59eacd6bc5 | |||
| 5ac528be05 | |||
| ad3c77b40e | |||
| e807d61b05 | |||
| 429213f29c | |||
| ace4fa1c0a | |||
| d543101054 | |||
| b1587f05cc | |||
| 9230b9a5dc | |||
| be65d0623b | |||
| 4221abe905 | |||
| a27ae7d4ab | |||
| cc53b862e4 | |||
| 49fc1537b7 | |||
| 1c013183f0 |
@@ -0,0 +1,19 @@
|
||||
module tanabata
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.10
|
||||
|
||||
require github.com/jackc/pgx/v5 v5.7.5
|
||||
|
||||
require (
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/pgx v3.6.2+incompatible // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/stretchr/testify v1.9.0 // indirect
|
||||
golang.org/x/crypto v0.37.0 // indirect
|
||||
golang.org/x/sync v0.13.0 // indirect
|
||||
golang.org/x/text v0.24.0 // indirect
|
||||
)
|
||||
@@ -0,0 +1,32 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx v3.6.2+incompatible h1:2zP5OD7kiyR3xzRYMhOcXVvkDZsImVXfj+yIyTQf3/o=
|
||||
github.com/jackc/pgx v3.6.2+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I=
|
||||
github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs=
|
||||
github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
|
||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
|
||||
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
|
||||
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
|
||||
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
||||
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
@@ -0,0 +1,119 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Name string `json:"name"`
|
||||
IsAdmin bool `json:"isAdmin"`
|
||||
CanCreate bool `json:"canCreate"`
|
||||
}
|
||||
|
||||
type MIME struct {
|
||||
Name string `json:"name"`
|
||||
Extension string `json:"extension"`
|
||||
}
|
||||
|
||||
type (
|
||||
CategoryCore struct {
|
||||
ID *string `json:"id"`
|
||||
Name *string `json:"name"`
|
||||
Color *string `json:"color"`
|
||||
}
|
||||
CategoryItem struct {
|
||||
CategoryCore
|
||||
}
|
||||
CategoryFull struct {
|
||||
CategoryCore
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Creator User `json:"creator"`
|
||||
Notes *string `json:"notes"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
FileCore struct {
|
||||
ID string `json:"id"`
|
||||
Name *string `json:"name"`
|
||||
MIME MIME `json:"mime"`
|
||||
}
|
||||
FileItem struct {
|
||||
FileCore
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Creator User `json:"creator"`
|
||||
}
|
||||
FileFull struct {
|
||||
FileCore
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Creator User `json:"creator"`
|
||||
Notes *string `json:"notes"`
|
||||
Metadata json.RawMessage `json:"metadata"`
|
||||
Viewed int `json:"viewed"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
TagCore struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Color *string `json:"color"`
|
||||
}
|
||||
TagItem struct {
|
||||
TagCore
|
||||
Category CategoryCore `json:"category"`
|
||||
}
|
||||
TagFull struct {
|
||||
TagCore
|
||||
Category CategoryCore `json:"category"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Creator User `json:"creator"`
|
||||
Notes *string `json:"notes"`
|
||||
UsedIncl int `json:"usedIncl"`
|
||||
UsedExcl int `json:"usedExcl"`
|
||||
}
|
||||
)
|
||||
|
||||
type Autotag struct {
|
||||
TriggerTag TagCore `json:"triggerTag"`
|
||||
AddTag TagCore `json:"addTag"`
|
||||
IsActive bool `json:"isActive"`
|
||||
}
|
||||
|
||||
type (
|
||||
PoolCore struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
PoolItem struct {
|
||||
PoolCore
|
||||
}
|
||||
PoolFull struct {
|
||||
PoolCore
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Creator User `json:"creator"`
|
||||
Notes *string `json:"notes"`
|
||||
Viewed int `json:"viewed"`
|
||||
}
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
ID int `json:"id"`
|
||||
UserAgent string `json:"userAgent"`
|
||||
StartedAt time.Time `json:"startedAt"`
|
||||
ExpiresAt time.Time `json:"expiresAt"`
|
||||
LastActivity time.Time `json:"lastActivity"`
|
||||
}
|
||||
|
||||
type Pagination struct {
|
||||
Total int `json:"total"`
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type Slice[T any] struct {
|
||||
Pagination Pagination `json:"pagination"`
|
||||
Data []T `json:"data"`
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package domain
|
||||
|
||||
import "fmt"
|
||||
|
||||
type ErrorCode string
|
||||
|
||||
const (
|
||||
// File errors
|
||||
ErrCodeFileNotFound ErrorCode = "FILE_NOT_FOUND"
|
||||
ErrCodeMIMENotSupported ErrorCode = "MIME_NOT_SUPPORTED"
|
||||
|
||||
// Tag errors
|
||||
ErrCodeTagNotFound ErrorCode = "TAG_NOT_FOUND"
|
||||
|
||||
// General errors
|
||||
ErrCodeBadRequest ErrorCode = "BAD_REQUEST"
|
||||
ErrCodeInternal ErrorCode = "INTERNAL_SERVER_ERROR"
|
||||
)
|
||||
|
||||
type DomainError struct {
|
||||
Err error `json:"-"`
|
||||
Code ErrorCode `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Details []any `json:"-"`
|
||||
}
|
||||
|
||||
func (e *DomainError) Wrap(err error) *DomainError {
|
||||
e.Err = err
|
||||
return e
|
||||
}
|
||||
|
||||
func NewErrorFileNotFound(file_id string) *DomainError {
|
||||
return &DomainError{
|
||||
Code: ErrCodeFileNotFound,
|
||||
Message: fmt.Sprintf("File not found: %q", file_id),
|
||||
}
|
||||
}
|
||||
|
||||
func NewErrorMIMENotSupported(mime string) *DomainError {
|
||||
return &DomainError{
|
||||
Code: ErrCodeMIMENotSupported,
|
||||
Message: fmt.Sprintf("MIME not supported: %q", mime),
|
||||
}
|
||||
}
|
||||
|
||||
func NewErrorTagNotFound(tag_id string) *DomainError {
|
||||
return &DomainError{
|
||||
Code: ErrCodeTagNotFound,
|
||||
Message: fmt.Sprintf("Tag not found: %q", tag_id),
|
||||
}
|
||||
}
|
||||
|
||||
func NewErrorBadRequest(message string) *DomainError {
|
||||
return &DomainError{
|
||||
Code: ErrCodeBadRequest,
|
||||
Message: message,
|
||||
}
|
||||
}
|
||||
|
||||
func NewErrorUnexpected() *DomainError {
|
||||
return &DomainError{
|
||||
Code: ErrCodeInternal,
|
||||
Message: "An unexpected error occured",
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FileRepository interface {
|
||||
GetAccess(ctx context.Context, user_id int, file_id string) (canView, canEdit bool, domainErr *DomainError)
|
||||
GetSlice(ctx context.Context, user_id int, filter, sort string, limit, offset int) (files Slice[FileItem], domainErr *DomainError)
|
||||
Get(ctx context.Context, user_id int, file_id string) (file FileFull, domainErr *DomainError)
|
||||
Add(ctx context.Context, user_id int, name, mime string, datetime time.Time, notes string, metadata json.RawMessage) (file FileCore, domainErr *DomainError)
|
||||
Update(ctx context.Context, file_id string, updates map[string]interface{}) (domainErr *DomainError)
|
||||
Delete(ctx context.Context, file_id string) (domainErr *DomainError)
|
||||
GetTags(ctx context.Context, user_id int, file_id string) (tags []TagItem, domainErr *DomainError)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"tanabata/internal/domain"
|
||||
)
|
||||
|
||||
// Initialize PostgreSQL database driver
|
||||
func New(dbURL string) (*pgxpool.Pool, error) {
|
||||
poolConfig, err := pgxpool.ParseConfig(dbURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse connection string: %w", err)
|
||||
}
|
||||
|
||||
poolConfig.MaxConns = 100
|
||||
poolConfig.MinConns = 0
|
||||
poolConfig.MaxConnLifetime = time.Hour
|
||||
poolConfig.HealthCheckPeriod = 30 * time.Second
|
||||
|
||||
ctx := context.Background()
|
||||
db, err := pgxpool.NewWithConfig(ctx, poolConfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize DB connections pool: %w", err)
|
||||
}
|
||||
if err = db.Ping(ctx); err != nil {
|
||||
return nil, fmt.Errorf("failed to ping database: %w", err)
|
||||
}
|
||||
return db, nil
|
||||
}
|
||||
|
||||
// Transaction wrapper
|
||||
func transaction(ctx context.Context, db *pgxpool.Pool, handler func(context.Context, pgx.Tx) *domain.DomainError) (domainErr *domain.DomainError) {
|
||||
tx, err := db.Begin(ctx)
|
||||
if err != nil {
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
return
|
||||
}
|
||||
domainErr = handler(ctx, tx)
|
||||
if domainErr != nil {
|
||||
tx.Rollback(ctx)
|
||||
return
|
||||
}
|
||||
err = tx.Commit(ctx)
|
||||
if err != nil {
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"tanabata/internal/domain"
|
||||
)
|
||||
|
||||
type FileRepository struct {
|
||||
db *pgxpool.Pool
|
||||
}
|
||||
|
||||
func NewFileRepository(db *pgxpool.Pool) *FileRepository {
|
||||
return &FileRepository{db: db}
|
||||
}
|
||||
|
||||
// Get user permissions on file
|
||||
func (s *FileRepository) GetAccess(ctx context.Context, user_id int, file_id string) (canView, canEdit bool, domainErr *domain.DomainError) {
|
||||
row := s.db.QueryRow(ctx, `
|
||||
SELECT
|
||||
COALESCE(a.view, FALSE) OR f.creator_id=$1 OR COALESCE(u.is_admin, FALSE),
|
||||
COALESCE(a.edit, FALSE) OR f.creator_id=$1 OR COALESCE(u.is_admin, FALSE)
|
||||
FROM data.files f
|
||||
LEFT JOIN acl.files a ON a.file_id=f.id AND a.user_id=$1
|
||||
LEFT JOIN system.users u ON u.id=$1
|
||||
WHERE f.id=$2
|
||||
`, user_id, file_id)
|
||||
err := row.Scan(&canView, &canEdit)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
domainErr = domain.NewErrorFileNotFound(file_id).Wrap(err)
|
||||
return
|
||||
}
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
switch pgErr.Code {
|
||||
case "22P02":
|
||||
domainErr = domain.NewErrorBadRequest(fmt.Sprintf("Invalid file id: %q", file_id)).Wrap(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Get a set of files
|
||||
func (s *FileRepository) GetSlice(ctx context.Context, user_id int, filter, sort string, limit, offset int) (files domain.Slice[domain.FileItem], domainErr *domain.DomainError) {
|
||||
filterCond, err := filterToSQL(filter)
|
||||
if err != nil {
|
||||
domainErr = domain.NewErrorBadRequest(fmt.Sprintf("Invalid filter string: %q", filter)).Wrap(err)
|
||||
return
|
||||
}
|
||||
sortExpr, err := sortToSQL(sort)
|
||||
if err != nil {
|
||||
domainErr = domain.NewErrorBadRequest(fmt.Sprintf("Invalid sorting parameter: %q", sort)).Wrap(err)
|
||||
return
|
||||
}
|
||||
// prepare query
|
||||
query := `
|
||||
SELECT
|
||||
f.id,
|
||||
f.name,
|
||||
m.name,
|
||||
m.extension,
|
||||
uuid_extract_timestamp(f.id),
|
||||
u.name,
|
||||
u.is_admin
|
||||
FROM data.files f
|
||||
JOIN system.mime m ON m.id=f.mime_id
|
||||
JOIN system.users u ON u.id=f.creator_id
|
||||
WHERE f.is_deleted IS FALSE AND (f.creator_id=$1 OR (SELECT view FROM acl.files WHERE file_id=f.id AND user_id=$1) OR (SELECT is_admin FROM system.users WHERE id=$1)) AND
|
||||
`
|
||||
query += filterCond
|
||||
queryCount := query
|
||||
query += sortExpr
|
||||
if limit >= 0 {
|
||||
query += fmt.Sprintf(" LIMIT %d", limit)
|
||||
}
|
||||
if offset > 0 {
|
||||
query += fmt.Sprintf(" OFFSET %d", offset)
|
||||
}
|
||||
// execute query
|
||||
domainErr = transaction(ctx, s.db, func(ctx context.Context, tx pgx.Tx) (domainErr *domain.DomainError) {
|
||||
rows, err := tx.Query(ctx, query, user_id)
|
||||
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
switch pgErr.Code {
|
||||
case "42P10":
|
||||
domainErr = domain.NewErrorBadRequest(fmt.Sprintf("Invalid sorting field: %q", sort[1:])).Wrap(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
count := 0
|
||||
for rows.Next() {
|
||||
var file domain.FileItem
|
||||
err = rows.Scan(&file.ID, &file.Name, &file.MIME.Name, &file.MIME.Extension, &file.CreatedAt, &file.Creator.Name, &file.Creator.IsAdmin)
|
||||
if err != nil {
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
return
|
||||
}
|
||||
files.Data = append(files.Data, file)
|
||||
count++
|
||||
}
|
||||
err = rows.Err()
|
||||
if err != nil {
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
return
|
||||
}
|
||||
files.Pagination.Limit = limit
|
||||
files.Pagination.Offset = offset
|
||||
files.Pagination.Count = count
|
||||
row := tx.QueryRow(ctx, fmt.Sprintf("SELECT COUNT(*) FROM (%s) tmp", queryCount), user_id)
|
||||
err = row.Scan(&files.Pagination.Total)
|
||||
if err != nil {
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
}
|
||||
return
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Get file
|
||||
func (s *FileRepository) Get(ctx context.Context, user_id int, file_id string) (file domain.FileFull, domainErr *domain.DomainError) {
|
||||
row := s.db.QueryRow(ctx, `
|
||||
SELECT
|
||||
f.id,
|
||||
f.name,
|
||||
m.name,
|
||||
m.extension,
|
||||
uuid_extract_timestamp(f.id),
|
||||
u.name,
|
||||
u.is_admin,
|
||||
f.notes,
|
||||
f.metadata,
|
||||
(SELECT COUNT(*) FROM activity.file_views fv WHERE fv.file_id=$2 AND fv.user_id=$1)
|
||||
FROM data.files f
|
||||
JOIN system.mime m ON m.id=f.mime_id
|
||||
JOIN system.users u ON u.id=f.creator_id
|
||||
WHERE f.is_deleted IS FALSE
|
||||
`, user_id, file_id)
|
||||
err := row.Scan(&file.ID, &file.Name, &file.MIME.Name, &file.MIME.Extension, &file.CreatedAt, &file.Creator.Name, &file.Creator.IsAdmin, &file.Notes, &file.Metadata, &file.Viewed)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
domainErr = domain.NewErrorFileNotFound(file_id).Wrap(err)
|
||||
return
|
||||
}
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
switch pgErr.Code {
|
||||
case "22P02":
|
||||
domainErr = domain.NewErrorBadRequest(fmt.Sprintf("Invalid file id: %q", file_id)).Wrap(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Add file
|
||||
func (s *FileRepository) Add(ctx context.Context, user_id int, name, mime string, datetime time.Time, notes string, metadata json.RawMessage) (file domain.FileCore, domainErr *domain.DomainError) {
|
||||
var mime_id int
|
||||
var extension string
|
||||
row := s.db.QueryRow(ctx, "SELECT id, extension FROM system.mime WHERE name=$1", mime)
|
||||
err := row.Scan(&mime_id, &extension)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
domainErr = domain.NewErrorMIMENotSupported(mime).Wrap(err)
|
||||
return
|
||||
}
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
return
|
||||
}
|
||||
row = s.db.QueryRow(ctx, `
|
||||
INSERT INTO data.files (name, mime_id, datetime, creator_id, notes, metadata)
|
||||
VALUES (NULLIF($1, ''), $2, $3, $4, NULLIF($5 ,''), $6)
|
||||
RETURNING id
|
||||
`, name, mime_id, datetime, user_id, notes, metadata)
|
||||
err = row.Scan(&file.ID)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
switch pgErr.Code {
|
||||
case "22007":
|
||||
domainErr = domain.NewErrorBadRequest(fmt.Sprintf("Invalid datetime: %q", datetime)).Wrap(err)
|
||||
return
|
||||
case "23502":
|
||||
domainErr = domain.NewErrorBadRequest("Unable to set NULL to some fields").Wrap(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
return
|
||||
}
|
||||
file.Name = &name
|
||||
file.MIME.Name = mime
|
||||
file.MIME.Extension = extension
|
||||
return
|
||||
}
|
||||
|
||||
// Update file
|
||||
func (s *FileRepository) Update(ctx context.Context, file_id string, updates map[string]interface{}) (domainErr *domain.DomainError) {
|
||||
if len(updates) == 0 {
|
||||
// domainErr = domain.NewErrorBadRequest(nil, "No fields provided for update")
|
||||
return
|
||||
}
|
||||
query := "UPDATE data.files SET"
|
||||
newValues := []interface{}{file_id}
|
||||
count := 2
|
||||
for field, value := range updates {
|
||||
switch field {
|
||||
case "name", "notes":
|
||||
query += fmt.Sprintf(" %s=NULLIF($%d, '')", field, count)
|
||||
case "datetime":
|
||||
query += fmt.Sprintf(" %s=NULLIF($%d, '')::timestamptz", field, count)
|
||||
case "metadata":
|
||||
query += fmt.Sprintf(" %s=NULLIF($%d, '')::jsonb", field, count)
|
||||
default:
|
||||
domainErr = domain.NewErrorBadRequest(fmt.Sprintf("Unknown field: %q", field))
|
||||
return
|
||||
}
|
||||
newValues = append(newValues, value)
|
||||
count++
|
||||
}
|
||||
query += fmt.Sprintf(" WHERE id=$1 AND is_deleted IS FALSE")
|
||||
commandTag, err := s.db.Exec(ctx, query, newValues...)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
switch pgErr.Code {
|
||||
case "22P02":
|
||||
domainErr = domain.NewErrorBadRequest("Invalid format of some values").Wrap(err)
|
||||
return
|
||||
case "22007":
|
||||
domainErr = domain.NewErrorBadRequest(fmt.Sprintf("Invalid datetime: %q", updates["datetime"])).Wrap(err)
|
||||
return
|
||||
case "23502":
|
||||
domainErr = domain.NewErrorBadRequest("Some fields cannot be empty").Wrap(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
return
|
||||
}
|
||||
if commandTag.RowsAffected() == 0 {
|
||||
domainErr = domain.NewErrorFileNotFound(file_id).Wrap(err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Delete file
|
||||
func (s *FileRepository) Delete(ctx context.Context, file_id string) (domainErr *domain.DomainError) {
|
||||
commandTag, err := s.db.Exec(ctx,
|
||||
"UPDATE data.files SET is_deleted=true WHERE id=$1 AND is_deleted IS FALSE",
|
||||
file_id)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
switch pgErr.Code {
|
||||
case "22P02":
|
||||
domainErr = domain.NewErrorBadRequest(fmt.Sprintf("Invalid file id: %q", file_id)).Wrap(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
return
|
||||
}
|
||||
if commandTag.RowsAffected() == 0 {
|
||||
domainErr = domain.NewErrorFileNotFound(file_id).Wrap(err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Get list of tags of file
|
||||
func (s *FileRepository) GetTags(ctx context.Context, user_id int, file_id string) (tags []domain.TagItem, domainErr *domain.DomainError) {
|
||||
rows, err := s.db.Query(ctx, `
|
||||
SELECT
|
||||
t.id,
|
||||
t.name,
|
||||
t.color,
|
||||
c.id,
|
||||
c.name,
|
||||
c.color
|
||||
FROM data.tags t
|
||||
LEFT JOIN data.categories c ON c.id=t.category_id
|
||||
JOIN data.file_tag ft ON ft.tag_id=t.id AND ft.file_id=$2
|
||||
JOIN data.files f ON f.id=$2
|
||||
WHERE NOT f.is_deleted AND (f.creator_id=$1 OR (SELECT view FROM acl.files WHERE file_id=$2 AND user_id=$1) OR (SELECT is_admin FROM system.users WHERE id=$1))
|
||||
`, user_id, file_id)
|
||||
if err != nil {
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) && (pgErr.Code == "22P02" || pgErr.Code == "22007") {
|
||||
domainErr = domain.NewErrorBadRequest(pgErr.Message).Wrap(err)
|
||||
return
|
||||
}
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var tag domain.TagItem
|
||||
err = rows.Scan(&tag.ID, &tag.Name, &tag.Color, &tag.Category.ID, &tag.Category.Name, &tag.Category.Color)
|
||||
if err != nil {
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
return
|
||||
}
|
||||
tags = append(tags, tag)
|
||||
}
|
||||
err = rows.Err()
|
||||
if err != nil {
|
||||
domainErr = domain.NewErrorUnexpected().Wrap(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
// Handle database error
|
||||
func handleDBError(errIn error) (statusCode int, err error) {
|
||||
if errIn == nil {
|
||||
statusCode = http.StatusOK
|
||||
return
|
||||
}
|
||||
if errors.Is(errIn, pgx.ErrNoRows) {
|
||||
err = fmt.Errorf("not found")
|
||||
statusCode = http.StatusNotFound
|
||||
return
|
||||
}
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(errIn, &pgErr) {
|
||||
switch pgErr.Code {
|
||||
case "22P02", "22007": // Invalid data format
|
||||
err = fmt.Errorf("%s", pgErr.Message)
|
||||
statusCode = http.StatusBadRequest
|
||||
return
|
||||
case "23505": // Unique constraint violation
|
||||
err = fmt.Errorf("already exists")
|
||||
statusCode = http.StatusConflict
|
||||
return
|
||||
}
|
||||
}
|
||||
return http.StatusInternalServerError, errIn
|
||||
}
|
||||
|
||||
// Convert "filter" URL param to SQL "WHERE" condition
|
||||
func filterToSQL(filter string) (sql string, err error) {
|
||||
// filterTokens := strings.Split(string(filter), ";")
|
||||
sql = "(true)"
|
||||
return
|
||||
}
|
||||
|
||||
// Convert "sort" URL param to SQL "ORDER BY"
|
||||
func sortToSQL(sort string) (sql string, err error) {
|
||||
if sort == "" {
|
||||
return
|
||||
}
|
||||
sortOptions := strings.Split(sort, ",")
|
||||
sql = " ORDER BY "
|
||||
for i, sortOption := range sortOptions {
|
||||
sortOrder := sortOption[:1]
|
||||
sortColumn := sortOption[1:]
|
||||
// parse sorting order marker
|
||||
switch sortOrder {
|
||||
case "+":
|
||||
sortOrder = "ASC"
|
||||
case "-":
|
||||
sortOrder = "DESC"
|
||||
default:
|
||||
err = fmt.Errorf("invalid sorting order mark: %q", sortOrder)
|
||||
return
|
||||
}
|
||||
// validate sorting column
|
||||
var n int
|
||||
n, err = strconv.Atoi(sortColumn)
|
||||
if err != nil || n < 0 {
|
||||
err = fmt.Errorf("invalid sorting column: %q", sortColumn)
|
||||
return
|
||||
}
|
||||
// add sorting option to query
|
||||
if i > 0 {
|
||||
sql += ","
|
||||
}
|
||||
sql += fmt.Sprintf("%s %s NULLS LAST", sortColumn, sortOrder)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"tanabata/internal/domain"
|
||||
)
|
||||
|
||||
type ErrorResponse struct {
|
||||
Error string `json:"error"`
|
||||
Code string `json:"code,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
type ErrorMapper struct{}
|
||||
|
||||
func (m *ErrorMapper) MapError(err domain.DomainError) (int, ErrorResponse) {
|
||||
switch err.Code {
|
||||
case domain.ErrCodeFileNotFound:
|
||||
return http.StatusNotFound, ErrorResponse{
|
||||
Error: "Not Found",
|
||||
Code: string(err.Code),
|
||||
Message: err.Message,
|
||||
}
|
||||
case domain.ErrCodeMIMENotSupported:
|
||||
return http.StatusNotFound, ErrorResponse{
|
||||
Error: "MIME not supported",
|
||||
Code: string(err.Code),
|
||||
Message: err.Message,
|
||||
}
|
||||
case domain.ErrCodeBadRequest:
|
||||
return http.StatusNotFound, ErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Code: string(err.Code),
|
||||
Message: err.Message,
|
||||
}
|
||||
}
|
||||
return http.StatusInternalServerError, ErrorResponse{
|
||||
Error: "Internal Server Error",
|
||||
Code: string(err.Code),
|
||||
Message: err.Message,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,592 @@
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 14.18 (Ubuntu 14.18-0ubuntu0.22.04.1)
|
||||
-- Dumped by pg_dump version 17.4
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET transaction_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: acl; Type: SCHEMA; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE SCHEMA acl;
|
||||
|
||||
|
||||
--
|
||||
-- Name: activity; Type: SCHEMA; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE SCHEMA activity;
|
||||
|
||||
|
||||
--
|
||||
-- Name: data; Type: SCHEMA; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE SCHEMA data;
|
||||
|
||||
|
||||
--
|
||||
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
-- *not* creating schema, since initdb creates it
|
||||
|
||||
|
||||
--
|
||||
-- Name: system; Type: SCHEMA; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE SCHEMA system;
|
||||
|
||||
|
||||
--
|
||||
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
|
||||
|
||||
|
||||
--
|
||||
-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions';
|
||||
|
||||
|
||||
--
|
||||
-- Name: uuid-ossp; Type: EXTENSION; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;
|
||||
|
||||
|
||||
--
|
||||
-- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)';
|
||||
|
||||
|
||||
--
|
||||
-- Name: add_file_to_tag_recursive(uuid, uuid); Type: FUNCTION; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION data.add_file_to_tag_recursive(f_id uuid, t_id uuid) RETURNS SETOF uuid
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
tmp uuid;
|
||||
tt_id uuid;
|
||||
ttt_id uuid;
|
||||
BEGIN
|
||||
INSERT INTO data.file_tag VALUES (f_id, t_id) ON CONFLICT DO NOTHING RETURNING tag_id INTO tmp;
|
||||
IF tmp IS NULL THEN
|
||||
RETURN;
|
||||
END IF;
|
||||
RETURN NEXT t_id;
|
||||
FOR tt_id IN
|
||||
SELECT a.add_tag_id FROM data.autotags a WHERE a.trigger_tag_id=t_id AND a.is_active
|
||||
LOOP
|
||||
FOR ttt_id IN SELECT data.add_file_to_tag_recursive(f_id, tt_id)
|
||||
LOOP
|
||||
RETURN NEXT ttt_id;
|
||||
END LOOP;
|
||||
END LOOP;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: uuid_extract_timestamp(uuid); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.uuid_extract_timestamp(uuid_val uuid) RETURNS timestamp with time zone
|
||||
LANGUAGE sql IMMUTABLE
|
||||
AS $$
|
||||
SELECT to_timestamp(
|
||||
('x' || LEFT(REPLACE(uuid_val::TEXT, '-', ''), 12))::BIT(48)::BIGINT
|
||||
/ 1000.0
|
||||
);
|
||||
$$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: uuid_v7(timestamp with time zone); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.uuid_v7(cts timestamp with time zone DEFAULT clock_timestamp()) RETURNS uuid
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
state text = current_setting('uuidv7.old_tp',true);
|
||||
old_tp text = split_part(state, ':',1);
|
||||
base int = coalesce(nullif(split_part(state,':',4),'')::int,(random()*16777215/2-1)::int);
|
||||
tp text;
|
||||
entropy text;
|
||||
seq text=base;
|
||||
seqn int=split_part(state,':',2);
|
||||
ver text = coalesce(split_part(state,':',3),to_hex(8+(random()*3)::int));
|
||||
BEGIN
|
||||
base = (random()*16777215/2-1)::int;
|
||||
tp = lpad(to_hex(floor(extract(epoch from cts)*1000)::int8),12,'0')||'7';
|
||||
if tp is distinct from old_tp then
|
||||
old_tp = tp;
|
||||
ver = to_hex(8+(random()*3)::int);
|
||||
base = (random()*16777215/2-1)::int;
|
||||
seqn = base;
|
||||
else
|
||||
seqn = seqn+(random()*1000)::int;
|
||||
end if;
|
||||
perform set_config('uuidv7.old_tp',old_tp||':'||seqn||':'||ver||':'||base, false);
|
||||
entropy = md5(gen_random_uuid()::text);
|
||||
seq = lpad(to_hex(seqn),6,'0');
|
||||
return (tp || substring(seq from 1 for 3) || ver || substring(seq from 4 for 3) ||
|
||||
substring(entropy from 1 for 12))::uuid;
|
||||
END
|
||||
$$;
|
||||
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: categories; Type: TABLE; Schema: acl; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE acl.categories (
|
||||
user_id smallint NOT NULL,
|
||||
category_id uuid NOT NULL,
|
||||
view boolean NOT NULL,
|
||||
edit boolean NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: files; Type: TABLE; Schema: acl; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE acl.files (
|
||||
user_id smallint NOT NULL,
|
||||
file_id uuid NOT NULL,
|
||||
view boolean NOT NULL,
|
||||
edit boolean NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: pools; Type: TABLE; Schema: acl; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE acl.pools (
|
||||
user_id smallint NOT NULL,
|
||||
pool_id uuid NOT NULL,
|
||||
view boolean NOT NULL,
|
||||
edit boolean NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tags; Type: TABLE; Schema: acl; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE acl.tags (
|
||||
user_id smallint NOT NULL,
|
||||
tag_id uuid NOT NULL,
|
||||
view boolean NOT NULL,
|
||||
edit boolean NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: file_views; Type: TABLE; Schema: activity; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE activity.file_views (
|
||||
file_id uuid NOT NULL,
|
||||
"timestamp" timestamp with time zone NOT NULL,
|
||||
user_id smallint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: pool_views; Type: TABLE; Schema: activity; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE activity.pool_views (
|
||||
pool_id uuid NOT NULL,
|
||||
"timestamp" timestamp with time zone NOT NULL,
|
||||
user_id smallint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: sessions; Type: TABLE; Schema: activity; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE activity.sessions (
|
||||
id integer NOT NULL,
|
||||
token text NOT NULL,
|
||||
user_id smallint NOT NULL,
|
||||
user_agent character varying(256) NOT NULL,
|
||||
started_at timestamp with time zone DEFAULT statement_timestamp() NOT NULL,
|
||||
expires_at timestamp with time zone,
|
||||
last_activity timestamp with time zone DEFAULT statement_timestamp() NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: sessions_id_seq; Type: SEQUENCE; Schema: activity; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE activity.sessions_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: sessions_id_seq; Type: SEQUENCE OWNED BY; Schema: activity; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE activity.sessions_id_seq OWNED BY activity.sessions.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag_uses; Type: TABLE; Schema: activity; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE activity.tag_uses (
|
||||
tag_id uuid NOT NULL,
|
||||
"timestamp" timestamp with time zone NOT NULL,
|
||||
user_id smallint NOT NULL,
|
||||
included boolean NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: autotags; Type: TABLE; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE data.autotags (
|
||||
trigger_tag_id uuid NOT NULL,
|
||||
add_tag_id uuid NOT NULL,
|
||||
is_active boolean DEFAULT true NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: categories; Type: TABLE; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE data.categories (
|
||||
id uuid DEFAULT public.uuid_v7() NOT NULL,
|
||||
name character varying(256) NOT NULL,
|
||||
notes text DEFAULT ''::text NOT NULL,
|
||||
color character(6),
|
||||
creator_id smallint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: file_pool; Type: TABLE; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE data.file_pool (
|
||||
file_id uuid NOT NULL,
|
||||
pool_id uuid NOT NULL,
|
||||
number smallint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: file_tag; Type: TABLE; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE data.file_tag (
|
||||
file_id uuid NOT NULL,
|
||||
tag_id uuid NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: files; Type: TABLE; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE data.files (
|
||||
id uuid DEFAULT public.uuid_v7() NOT NULL,
|
||||
name character varying(256),
|
||||
mime_id smallint NOT NULL,
|
||||
datetime timestamp with time zone DEFAULT clock_timestamp() NOT NULL,
|
||||
notes text,
|
||||
metadata jsonb NOT NULL,
|
||||
creator_id smallint NOT NULL,
|
||||
is_deleted boolean DEFAULT false NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: pools; Type: TABLE; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE data.pools (
|
||||
id uuid DEFAULT public.uuid_v7() NOT NULL,
|
||||
name character varying(256) NOT NULL,
|
||||
notes text,
|
||||
creator_id smallint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tags; Type: TABLE; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE data.tags (
|
||||
id uuid DEFAULT public.uuid_v7() NOT NULL,
|
||||
name character varying(256) NOT NULL,
|
||||
notes text,
|
||||
color character(6),
|
||||
category_id uuid,
|
||||
creator_id smallint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: mime; Type: TABLE; Schema: system; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE system.mime (
|
||||
id smallint NOT NULL,
|
||||
name character varying(127) NOT NULL,
|
||||
extension character varying(16) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: mime_id_seq; Type: SEQUENCE; Schema: system; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE system.mime_id_seq
|
||||
AS smallint
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: mime_id_seq; Type: SEQUENCE OWNED BY; Schema: system; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE system.mime_id_seq OWNED BY system.mime.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: users; Type: TABLE; Schema: system; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE system.users (
|
||||
id smallint NOT NULL,
|
||||
name character varying(32) NOT NULL,
|
||||
password text NOT NULL,
|
||||
is_admin boolean DEFAULT false NOT NULL,
|
||||
can_create boolean DEFAULT false NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users_id_seq; Type: SEQUENCE; Schema: system; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE system.users_id_seq
|
||||
AS smallint
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: system; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE system.users_id_seq OWNED BY system.users.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: sessions id; Type: DEFAULT; Schema: activity; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY activity.sessions ALTER COLUMN id SET DEFAULT nextval('activity.sessions_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: mime id; Type: DEFAULT; Schema: system; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY system.mime ALTER COLUMN id SET DEFAULT nextval('system.mime_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users id; Type: DEFAULT; Schema: system; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY system.users ALTER COLUMN id SET DEFAULT nextval('system.users_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: categories categories_pkey; Type: CONSTRAINT; Schema: acl; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY acl.categories
|
||||
ADD CONSTRAINT categories_pkey PRIMARY KEY (user_id, category_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: files files_pkey; Type: CONSTRAINT; Schema: acl; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY acl.files
|
||||
ADD CONSTRAINT files_pkey PRIMARY KEY (user_id, file_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: pools pools_pkey; Type: CONSTRAINT; Schema: acl; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY acl.pools
|
||||
ADD CONSTRAINT pools_pkey PRIMARY KEY (user_id, pool_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tags tags_pkey; Type: CONSTRAINT; Schema: acl; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY acl.tags
|
||||
ADD CONSTRAINT tags_pkey PRIMARY KEY (user_id, tag_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: file_views file_views_pkey; Type: CONSTRAINT; Schema: activity; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY activity.file_views
|
||||
ADD CONSTRAINT file_views_pkey PRIMARY KEY (file_id, "timestamp", user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: pool_views pool_views_pkey; Type: CONSTRAINT; Schema: activity; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY activity.pool_views
|
||||
ADD CONSTRAINT pool_views_pkey PRIMARY KEY (pool_id, "timestamp", user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: sessions sessions_pkey; Type: CONSTRAINT; Schema: activity; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY activity.sessions
|
||||
ADD CONSTRAINT sessions_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag_uses tag_uses_pkey; Type: CONSTRAINT; Schema: activity; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY activity.tag_uses
|
||||
ADD CONSTRAINT tag_uses_pkey PRIMARY KEY (tag_id, "timestamp", user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: autotags autotags_pkey; Type: CONSTRAINT; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY data.autotags
|
||||
ADD CONSTRAINT autotags_pkey PRIMARY KEY (trigger_tag_id, add_tag_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: categories categories_pkey; Type: CONSTRAINT; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY data.categories
|
||||
ADD CONSTRAINT categories_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: file_pool file_pool_pkey; Type: CONSTRAINT; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY data.file_pool
|
||||
ADD CONSTRAINT file_pool_pkey PRIMARY KEY (file_id, pool_id, number);
|
||||
|
||||
|
||||
--
|
||||
-- Name: file_tag file_tag_pkey; Type: CONSTRAINT; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY data.file_tag
|
||||
ADD CONSTRAINT file_tag_pkey PRIMARY KEY (file_id, tag_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: files files_pkey; Type: CONSTRAINT; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY data.files
|
||||
ADD CONSTRAINT files_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: pools pools_pkey; Type: CONSTRAINT; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY data.pools
|
||||
ADD CONSTRAINT pools_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tags tags_pkey; Type: CONSTRAINT; Schema: data; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY data.tags
|
||||
ADD CONSTRAINT tags_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: mime mime_pkey; Type: CONSTRAINT; Schema: system; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY system.mime
|
||||
ADD CONSTRAINT mime_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users users_pkey; Type: CONSTRAINT; Schema: system; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY system.users
|
||||
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
+212
-208
@@ -1,208 +1,212 @@
|
||||
@startuml Tanabata File Manager entity relationship diagram
|
||||
|
||||
' skinparam linetype ortho
|
||||
|
||||
|
||||
' ========== SYSTEM ==========
|
||||
|
||||
entity "system.users" as usr {
|
||||
* id : uuid <<generated>>
|
||||
--
|
||||
* name : varchar(32)
|
||||
* password : text
|
||||
* is_admin : boolean
|
||||
}
|
||||
|
||||
entity "system.mime" as mime {
|
||||
* name : varchar(127)
|
||||
--
|
||||
* extension : varchar(16)
|
||||
}
|
||||
|
||||
|
||||
' ========== DATA ==========
|
||||
|
||||
entity "data.categories" as cty {
|
||||
* id : uuid <<generated>>
|
||||
--
|
||||
* name : varchar(256)
|
||||
notes : text
|
||||
color : char(6)
|
||||
* created_at : timestamptz <<generated>>
|
||||
* creator_id : uuid
|
||||
' * is_private : boolean
|
||||
}
|
||||
|
||||
cty::creator_id }o--|| usr::id
|
||||
|
||||
entity "data.files" as fle {
|
||||
* id : uuid <<generated>>
|
||||
--
|
||||
name : varchar(256)
|
||||
* mime : varchar(127)
|
||||
* datetime : timestamptz
|
||||
notes : text
|
||||
* metadata : jsonb
|
||||
* created_at : timestamptz <<generated>>
|
||||
* creator_id : uuid
|
||||
' * is_private : boolean
|
||||
}
|
||||
|
||||
fle::mime }o--|| mime::name
|
||||
fle::creator_id }o--|| usr::id
|
||||
|
||||
entity "data.tags" as tag {
|
||||
* id : uuid <<generated>>
|
||||
--
|
||||
* name : varchar(256)
|
||||
notes : text
|
||||
color : char(6)
|
||||
category_id : uuid
|
||||
* created_at : timestamptz <<generated>>
|
||||
* creator_id : uuid
|
||||
' * is_private : boolean
|
||||
}
|
||||
|
||||
tag::category_id }o--o| cty::id
|
||||
tag::creator_id }o--|| usr::id
|
||||
|
||||
entity "data.file_tag" as ft {
|
||||
* file_id : uuid
|
||||
* tag_id : uuid
|
||||
}
|
||||
|
||||
ft::file_id }o--|| fle::id
|
||||
ft::tag_id }o--|| tag::id
|
||||
|
||||
entity "data.autotags" as atg {
|
||||
* trigger_tag_id : uuid
|
||||
* add_tag_id : uuid
|
||||
--
|
||||
* is_active : boolean
|
||||
}
|
||||
|
||||
atg::trigger_tag_id }o--|| tag::id
|
||||
atg::add_tag_id }o--|| tag::id
|
||||
|
||||
entity "data.pools" as pool {
|
||||
* id : uuid <<generated>>
|
||||
--
|
||||
* name : varchar(256)
|
||||
notes : text
|
||||
' parent_id : uuid
|
||||
* created_at : timestamptz
|
||||
* creator_id : uuid
|
||||
' * is_private : boolean
|
||||
}
|
||||
|
||||
pool::creator_id }o--|| usr::id
|
||||
' pool::parent_id }o--o| pool::id
|
||||
|
||||
entity "data.file_pool" as fp {
|
||||
* file_id : uuid
|
||||
* pool_id : uuid
|
||||
* number : integer
|
||||
}
|
||||
|
||||
fp::file_id }o--|| fle::id
|
||||
fp::pool_id }o--|| pool::id
|
||||
|
||||
|
||||
' ========== ACCESS ==========
|
||||
|
||||
entity "access.files" as acl_f {
|
||||
* user_id : uuid
|
||||
* file_id : uuid
|
||||
--
|
||||
* read : boolean
|
||||
* write : boolean
|
||||
}
|
||||
|
||||
acl_f::user_id }o--|| usr::id
|
||||
acl_f::file_id }o--|| fle::id
|
||||
|
||||
entity "access.tags" as acl_t {
|
||||
* user_id : uuid
|
||||
* tag_id : uuid
|
||||
--
|
||||
* read : boolean
|
||||
* write : boolean
|
||||
' * files_read : boolean
|
||||
' * files_write : boolean
|
||||
}
|
||||
|
||||
acl_t::user_id }o--|| usr::id
|
||||
acl_t::tag_id }o--|| tag::id
|
||||
|
||||
entity "access.categories" as acl_c {
|
||||
* user_id : uuid
|
||||
* category_id : uuid
|
||||
--
|
||||
* read : boolean
|
||||
* write : boolean
|
||||
' * tags_read : boolean
|
||||
' * tags_write : boolean
|
||||
}
|
||||
|
||||
acl_c::user_id }o--|| usr::id
|
||||
acl_c::category_id }o--|| cty::id
|
||||
|
||||
entity "access.pools" as acl_p {
|
||||
* user_id : uuid
|
||||
* pool_id : uuid
|
||||
--
|
||||
* read : boolean
|
||||
* write : boolean
|
||||
' * files_read : boolean
|
||||
' * files_write : boolean
|
||||
}
|
||||
|
||||
acl_p::user_id }o--|| usr::id
|
||||
acl_p::pool_id }o--|| pool::id
|
||||
|
||||
|
||||
' ========== ACTIVITY ==========
|
||||
|
||||
entity "activity.sessions" as ssn {
|
||||
* id : uuid <<generated>>
|
||||
--
|
||||
* user_id : uuid
|
||||
* user_agent : varchar(512)
|
||||
* started_at : timestamptz
|
||||
expires_at : timestamptz
|
||||
* last_activity : timestamptz
|
||||
}
|
||||
|
||||
ssn::user_id }o--|| usr::id
|
||||
|
||||
entity "activity.file_views" as fv {
|
||||
* file_id : uuid
|
||||
* timestamp : timestamptz
|
||||
* user_id : uuid
|
||||
}
|
||||
|
||||
fv::file_id }o--|| fle::id
|
||||
fv::user_id }o--|| usr::id
|
||||
|
||||
entity "activity.tag_uses" as tu {
|
||||
* tag_id : uuid
|
||||
* timestamp : timestamptz
|
||||
* user_id : uuid
|
||||
--
|
||||
* included : boolean
|
||||
}
|
||||
|
||||
tu::tag_id }o--|| tag::id
|
||||
tu::user_id }o--|| usr::id
|
||||
|
||||
entity "activity.pool_views" as pv {
|
||||
* pool_id : uuid
|
||||
* timestamp : timestamptz
|
||||
* user_id : uuid
|
||||
}
|
||||
|
||||
pv::pool_id }o--|| pool::id
|
||||
pv::user_id }o--|| usr::id
|
||||
|
||||
|
||||
@enduml
|
||||
@startuml Tanabata File Manager entity relationship diagram
|
||||
|
||||
' skinparam linetype ortho
|
||||
|
||||
|
||||
' ========== SYSTEM ==========
|
||||
|
||||
entity "system.users" as usr {
|
||||
* id : smallserial <<generated>>
|
||||
--
|
||||
* name : varchar(32)
|
||||
* password : text
|
||||
* is_admin : boolean
|
||||
* can_create : boolean
|
||||
}
|
||||
|
||||
entity "system.mime" as mime {
|
||||
* id : smallserial <<generated>>
|
||||
--
|
||||
* name : varchar(127)
|
||||
* extension : varchar(16)
|
||||
}
|
||||
|
||||
|
||||
' ========== DATA ==========
|
||||
|
||||
entity "data.categories" as cty {
|
||||
* id : uuid <<generated>>
|
||||
--
|
||||
* name : varchar(256)
|
||||
notes : text
|
||||
color : char(6)
|
||||
' * created_at : timestamptz <<generated>>
|
||||
* creator_id : smallint
|
||||
' * is_private : boolean
|
||||
}
|
||||
|
||||
cty::creator_id }o--|| usr::id
|
||||
|
||||
entity "data.files" as fle {
|
||||
* id : uuid <<generated>>
|
||||
--
|
||||
name : varchar(256)
|
||||
* mime_id : smallint
|
||||
* datetime : timestamptz
|
||||
notes : text
|
||||
* metadata : jsonb
|
||||
' * created_at : timestamptz <<generated>>
|
||||
* creator_id : smallint
|
||||
' * is_private : boolean
|
||||
* is_deleted : boolean
|
||||
}
|
||||
|
||||
fle::mime_id }o--|| mime::id
|
||||
fle::creator_id }o--|| usr::id
|
||||
|
||||
entity "data.tags" as tag {
|
||||
* id : uuid <<generated>>
|
||||
--
|
||||
* name : varchar(256)
|
||||
notes : text
|
||||
color : char(6)
|
||||
category_id : uuid
|
||||
' * created_at : timestamptz <<generated>>
|
||||
* creator_id : smallint
|
||||
' * is_private : boolean
|
||||
}
|
||||
|
||||
tag::category_id }o--o| cty::id
|
||||
tag::creator_id }o--|| usr::id
|
||||
|
||||
entity "data.file_tag" as ft {
|
||||
* file_id : uuid
|
||||
* tag_id : uuid
|
||||
}
|
||||
|
||||
ft::file_id }o--|| fle::id
|
||||
ft::tag_id }o--|| tag::id
|
||||
|
||||
entity "data.autotags" as atg {
|
||||
* trigger_tag_id : uuid
|
||||
* add_tag_id : uuid
|
||||
--
|
||||
* is_active : boolean
|
||||
}
|
||||
|
||||
atg::trigger_tag_id }o--|| tag::id
|
||||
atg::add_tag_id }o--|| tag::id
|
||||
|
||||
entity "data.pools" as pool {
|
||||
* id : uuid <<generated>>
|
||||
--
|
||||
* name : varchar(256)
|
||||
notes : text
|
||||
' parent_id : uuid
|
||||
' * created_at : timestamptz
|
||||
* creator_id : smallint
|
||||
' * is_private : boolean
|
||||
}
|
||||
|
||||
pool::creator_id }o--|| usr::id
|
||||
' pool::parent_id }o--o| pool::id
|
||||
|
||||
entity "data.file_pool" as fp {
|
||||
* file_id : uuid
|
||||
* pool_id : uuid
|
||||
* number : smallint
|
||||
}
|
||||
|
||||
fp::file_id }o--|| fle::id
|
||||
fp::pool_id }o--|| pool::id
|
||||
|
||||
|
||||
' ========== ACL ==========
|
||||
|
||||
entity "acl.files" as acl_f {
|
||||
* user_id : smallint
|
||||
* file_id : uuid
|
||||
--
|
||||
* view : boolean
|
||||
* edit : boolean
|
||||
}
|
||||
|
||||
acl_f::user_id }o--|| usr::id
|
||||
acl_f::file_id }o--|| fle::id
|
||||
|
||||
entity "acl.tags" as acl_t {
|
||||
* user_id : smallint
|
||||
* tag_id : uuid
|
||||
--
|
||||
* view : boolean
|
||||
* edit : boolean
|
||||
' * files_view : boolean
|
||||
' * files_edit : boolean
|
||||
}
|
||||
|
||||
acl_t::user_id }o--|| usr::id
|
||||
acl_t::tag_id }o--|| tag::id
|
||||
|
||||
entity "acl.categories" as acl_c {
|
||||
* user_id : smallint
|
||||
* category_id : uuid
|
||||
--
|
||||
* view : boolean
|
||||
* edit : boolean
|
||||
' * tags_view : boolean
|
||||
' * tags_edit : boolean
|
||||
}
|
||||
|
||||
acl_c::user_id }o--|| usr::id
|
||||
acl_c::category_id }o--|| cty::id
|
||||
|
||||
entity "acl.pools" as acl_p {
|
||||
* user_id : smallint
|
||||
* pool_id : uuid
|
||||
--
|
||||
* view : boolean
|
||||
* edit : boolean
|
||||
' * files_view : boolean
|
||||
' * files_edit : boolean
|
||||
}
|
||||
|
||||
acl_p::user_id }o--|| usr::id
|
||||
acl_p::pool_id }o--|| pool::id
|
||||
|
||||
|
||||
' ========== ACTIVITY ==========
|
||||
|
||||
entity "activity.sessions" as ssn {
|
||||
* id : serial <<generated>>
|
||||
--
|
||||
* token : text
|
||||
* user_id : smallint
|
||||
* user_agent : varchar(512)
|
||||
* started_at : timestamptz
|
||||
expires_at : timestamptz
|
||||
* last_activity : timestamptz
|
||||
}
|
||||
|
||||
ssn::user_id }o--|| usr::id
|
||||
|
||||
entity "activity.file_views" as fv {
|
||||
* file_id : uuid
|
||||
* timestamp : timestamptz
|
||||
* user_id : smallint
|
||||
}
|
||||
|
||||
fv::file_id }o--|| fle::id
|
||||
fv::user_id }o--|| usr::id
|
||||
|
||||
entity "activity.tag_uses" as tu {
|
||||
* tag_id : uuid
|
||||
* timestamp : timestamptz
|
||||
* user_id : smallint
|
||||
--
|
||||
* included : boolean
|
||||
}
|
||||
|
||||
tu::tag_id }o--|| tag::id
|
||||
tu::user_id }o--|| usr::id
|
||||
|
||||
entity "activity.pool_views" as pv {
|
||||
* pool_id : uuid
|
||||
* timestamp : timestamptz
|
||||
* user_id : smallint
|
||||
}
|
||||
|
||||
pv::pool_id }o--|| pool::id
|
||||
pv::user_id }o--|| usr::id
|
||||
|
||||
|
||||
@enduml
|
||||
|
||||
Reference in New Issue
Block a user