Rename all the db tables
This commit is contained in:
parent
a147cfa325
commit
0e56f56372
|
@ -19,5 +19,5 @@ pushd $BETA_PATH
|
||||||
|
|
||||||
docker-compose exec postgres bash -c "psql -U postgres -c \"CREATE ROLE hmn CREATEDB LOGIN PASSWORD 'password';\""
|
docker-compose exec postgres bash -c "psql -U postgres -c \"CREATE ROLE hmn CREATEDB LOGIN PASSWORD 'password';\""
|
||||||
popd
|
popd
|
||||||
go run src/main.go seedfile local/backups/hmn_pg_dump_live_2021-11-14
|
go run src/main.go db seedfile local/backups/hmn_pg_dump_live_2021-11-14
|
||||||
# go run src/main.go seedfile local/backups/hmn_pg_dump_live_2021-10-23
|
# go run src/main.go db seedfile local/backups/hmn_pg_dump_live_2021-10-23
|
||||||
|
|
|
@ -30,7 +30,7 @@ echo "Running migrations..."
|
||||||
systemctl stop hmn
|
systemctl stop hmn
|
||||||
do_as hmn <<'SCRIPT'
|
do_as hmn <<'SCRIPT'
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
/home/hmn/bin/hmn migrate
|
/home/hmn/bin/hmn db migrate
|
||||||
SCRIPT
|
SCRIPT
|
||||||
systemctl start hmn
|
systemctl start hmn
|
||||||
|
|
||||||
|
|
|
@ -377,8 +377,8 @@ ${BLUE_BOLD}Download and restore a database backup${RESET}
|
||||||
|
|
||||||
su hmn
|
su hmn
|
||||||
cd ~
|
cd ~
|
||||||
hmn seedfile <your backup file>
|
hmn db seedfile <your backup file>
|
||||||
hmn migrate
|
hmn db migrate
|
||||||
|
|
||||||
${BLUE_BOLD}Restore static files${RESET}
|
${BLUE_BOLD}Restore static files${RESET}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ func addCreateProjectCommand(projectCommand *cobra.Command) {
|
||||||
|
|
||||||
newProjectID, err := db.QueryOneScalar[int](ctx, tx,
|
newProjectID, err := db.QueryOneScalar[int](ctx, tx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_project (
|
INSERT INTO project (
|
||||||
slug,
|
slug,
|
||||||
name,
|
name,
|
||||||
blurb,
|
blurb,
|
||||||
|
@ -121,7 +121,7 @@ func addCreateProjectCommand(projectCommand *cobra.Command) {
|
||||||
for _, userID := range userIDs {
|
for _, userID := range userIDs {
|
||||||
_, err := tx.Exec(ctx,
|
_, err := tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_user_projects (user_id, project_id)
|
INSERT INTO user_project (user_id, project_id)
|
||||||
VALUES ($1, $2)
|
VALUES ($1, $2)
|
||||||
`,
|
`,
|
||||||
userID,
|
userID,
|
||||||
|
|
|
@ -45,7 +45,7 @@ func init() {
|
||||||
conn := db.NewConnPool(1, 1)
|
conn := db.NewConnPool(1, 1)
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
row := conn.QueryRow(ctx, "SELECT id, username FROM auth_user WHERE lower(username) = lower($1)", username)
|
row := conn.QueryRow(ctx, "SELECT id, username FROM hmn_user WHERE lower(username) = lower($1)", username)
|
||||||
var id int
|
var id int
|
||||||
var canonicalUsername string
|
var canonicalUsername string
|
||||||
err := row.Scan(&id, &canonicalUsername)
|
err := row.Scan(&id, &canonicalUsername)
|
||||||
|
@ -86,7 +86,7 @@ func init() {
|
||||||
conn := db.NewConnPool(1, 1)
|
conn := db.NewConnPool(1, 1)
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
res, err := conn.Exec(ctx, "UPDATE auth_user SET status = $1 WHERE LOWER(username) = LOWER($2);", models.UserStatusConfirmed, username)
|
res, err := conn.Exec(ctx, "UPDATE hmn_user SET status = $1 WHERE LOWER(username) = LOWER($2);", models.UserStatusConfirmed, username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ func init() {
|
||||||
conn := db.NewConnPool(1, 1)
|
conn := db.NewConnPool(1, 1)
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
res, err := conn.Exec(ctx, "UPDATE auth_user SET status = $1 WHERE LOWER(username) = LOWER($2);", status, username)
|
res, err := conn.Exec(ctx, "UPDATE hmn_user SET status = $1 WHERE LOWER(username) = LOWER($2);", status, username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ func init() {
|
||||||
}
|
}
|
||||||
defer tx.Rollback(ctx)
|
defer tx.Rollback(ctx)
|
||||||
|
|
||||||
projectId, err := db.QueryOneScalar[int](ctx, tx, `SELECT id FROM handmade_project WHERE slug = $1`, projectSlug)
|
projectId, err := db.QueryOneScalar[int](ctx, tx, `SELECT id FROM project WHERE slug = $1`, projectSlug)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ func init() {
|
||||||
if parentSlug == "" {
|
if parentSlug == "" {
|
||||||
// Select the root subforum
|
// Select the root subforum
|
||||||
id, err := db.QueryOneScalar[int](ctx, tx,
|
id, err := db.QueryOneScalar[int](ctx, tx,
|
||||||
`SELECT id FROM handmade_subforum WHERE parent_id IS NULL AND project_id = $1`,
|
`SELECT id FROM subforum WHERE parent_id IS NULL AND project_id = $1`,
|
||||||
projectId,
|
projectId,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -229,7 +229,7 @@ func init() {
|
||||||
} else {
|
} else {
|
||||||
// Select the parent
|
// Select the parent
|
||||||
id, err := db.QueryOneScalar[int](ctx, tx,
|
id, err := db.QueryOneScalar[int](ctx, tx,
|
||||||
`SELECT id FROM handmade_subforum WHERE slug = $1 AND project_id = $2`,
|
`SELECT id FROM subforum WHERE slug = $1 AND project_id = $2`,
|
||||||
parentSlug, projectId,
|
parentSlug, projectId,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -240,7 +240,7 @@ func init() {
|
||||||
|
|
||||||
newId, err := db.QueryOneScalar[int](ctx, tx,
|
newId, err := db.QueryOneScalar[int](ctx, tx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_subforum (name, slug, blurb, parent_id, project_id)
|
INSERT INTO subforum (name, slug, blurb, parent_id, project_id)
|
||||||
VALUES ($1, $2, $3, $4, $5)
|
VALUES ($1, $2, $3, $4, $5)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`,
|
`,
|
||||||
|
@ -289,13 +289,13 @@ func init() {
|
||||||
}
|
}
|
||||||
defer tx.Rollback(ctx)
|
defer tx.Rollback(ctx)
|
||||||
|
|
||||||
projectId, err := db.QueryOneScalar[int](ctx, tx, `SELECT id FROM handmade_project WHERE slug = $1`, projectSlug)
|
projectId, err := db.QueryOneScalar[int](ctx, tx, `SELECT id FROM project WHERE slug = $1`, projectSlug)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subforumId, err := db.QueryOneScalar[int](ctx, tx,
|
subforumId, err := db.QueryOneScalar[int](ctx, tx,
|
||||||
`SELECT id FROM handmade_subforum WHERE slug = $1 AND project_id = $2`,
|
`SELECT id FROM subforum WHERE slug = $1 AND project_id = $2`,
|
||||||
subforumSlug, projectId,
|
subforumSlug, projectId,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -314,7 +314,7 @@ func init() {
|
||||||
|
|
||||||
threadsTag, err := tx.Exec(ctx,
|
threadsTag, err := tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_thread
|
UPDATE thread
|
||||||
SET
|
SET
|
||||||
project_id = $2,
|
project_id = $2,
|
||||||
subforum_id = $3,
|
subforum_id = $3,
|
||||||
|
@ -330,7 +330,7 @@ func init() {
|
||||||
|
|
||||||
postsTag, err := tx.Exec(ctx,
|
postsTag, err := tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_post
|
UPDATE post
|
||||||
SET
|
SET
|
||||||
thread_type = 2
|
thread_type = 2
|
||||||
WHERE
|
WHERE
|
||||||
|
|
|
@ -122,7 +122,7 @@ func Create(ctx context.Context, dbConn db.ConnOrTx, in CreateInput) (*models.As
|
||||||
// TODO(db): Would be convient to use RETURNING here...
|
// TODO(db): Would be convient to use RETURNING here...
|
||||||
_, err = dbConn.Exec(ctx,
|
_, err = dbConn.Exec(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_asset (id, s3_key, filename, size, mime_type, sha1sum, width, height, uploader_id)
|
INSERT INTO asset (id, s3_key, filename, size, mime_type, sha1sum, width, height, uploader_id)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||||
`,
|
`,
|
||||||
id,
|
id,
|
||||||
|
@ -143,7 +143,7 @@ func Create(ctx context.Context, dbConn db.ConnOrTx, in CreateInput) (*models.As
|
||||||
asset, err := db.QueryOne[models.Asset](ctx, dbConn,
|
asset, err := db.QueryOne[models.Asset](ctx, dbConn,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_asset
|
FROM asset
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -180,7 +180,7 @@ func HashPassword(password string) HashedPassword {
|
||||||
var ErrUserDoesNotExist = errors.New("user does not exist")
|
var ErrUserDoesNotExist = errors.New("user does not exist")
|
||||||
|
|
||||||
func UpdatePassword(ctx context.Context, conn db.ConnOrTx, username string, hp HashedPassword) error {
|
func UpdatePassword(ctx context.Context, conn db.ConnOrTx, username string, hp HashedPassword) error {
|
||||||
tag, err := conn.Exec(ctx, "UPDATE auth_user SET password = $1 WHERE username = $2", hp.String(), username)
|
tag, err := conn.Exec(ctx, "UPDATE hmn_user SET password = $1 WHERE username = $2", hp.String(), username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return oops.New(err, "failed to update password")
|
return oops.New(err, "failed to update password")
|
||||||
} else if tag.RowsAffected() < 1 {
|
} else if tag.RowsAffected() < 1 {
|
||||||
|
@ -193,10 +193,10 @@ func UpdatePassword(ctx context.Context, conn db.ConnOrTx, username string, hp H
|
||||||
func DeleteInactiveUsers(ctx context.Context, conn *pgxpool.Pool) (int64, error) {
|
func DeleteInactiveUsers(ctx context.Context, conn *pgxpool.Pool) (int64, error) {
|
||||||
tag, err := conn.Exec(ctx,
|
tag, err := conn.Exec(ctx,
|
||||||
`
|
`
|
||||||
DELETE FROM auth_user
|
DELETE FROM hmn_user
|
||||||
WHERE
|
WHERE
|
||||||
status = $1 AND
|
status = $1 AND
|
||||||
(SELECT COUNT(*) as ct FROM handmade_onetimetoken AS ott WHERE ott.owner_id = auth_user.id AND ott.expires < $2 AND ott.token_type = $3) > 0;
|
(SELECT COUNT(*) as ct FROM one_time_token AS ott WHERE ott.owner_id = hmn_user.id AND ott.expires < $2 AND ott.token_type = $3) > 0;
|
||||||
`,
|
`,
|
||||||
models.UserStatusInactive,
|
models.UserStatusInactive,
|
||||||
time.Now(),
|
time.Now(),
|
||||||
|
@ -213,7 +213,7 @@ func DeleteInactiveUsers(ctx context.Context, conn *pgxpool.Pool) (int64, error)
|
||||||
func DeleteExpiredPasswordResets(ctx context.Context, conn *pgxpool.Pool) (int64, error) {
|
func DeleteExpiredPasswordResets(ctx context.Context, conn *pgxpool.Pool) (int64, error) {
|
||||||
tag, err := conn.Exec(ctx,
|
tag, err := conn.Exec(ctx,
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_onetimetoken
|
DELETE FROM one_time_token
|
||||||
WHERE
|
WHERE
|
||||||
token_type = $1
|
token_type = $1
|
||||||
AND expires < $2
|
AND expires < $2
|
||||||
|
|
|
@ -45,7 +45,7 @@ func makeCSRFToken() string {
|
||||||
var ErrNoSession = errors.New("no session found")
|
var ErrNoSession = errors.New("no session found")
|
||||||
|
|
||||||
func GetSession(ctx context.Context, conn *pgxpool.Pool, id string) (*models.Session, error) {
|
func GetSession(ctx context.Context, conn *pgxpool.Pool, id string) (*models.Session, error) {
|
||||||
sess, err := db.QueryOne[models.Session](ctx, conn, "SELECT $columns FROM sessions WHERE id = $1", id)
|
sess, err := db.QueryOne[models.Session](ctx, conn, "SELECT $columns FROM session WHERE id = $1", id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, db.NotFound) {
|
if errors.Is(err, db.NotFound) {
|
||||||
return nil, ErrNoSession
|
return nil, ErrNoSession
|
||||||
|
@ -66,7 +66,7 @@ func CreateSession(ctx context.Context, conn *pgxpool.Pool, username string) (*m
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := conn.Exec(ctx,
|
_, err := conn.Exec(ctx,
|
||||||
"INSERT INTO sessions (id, username, expires_at, csrf_token) VALUES ($1, $2, $3, $4)",
|
"INSERT INTO session (id, username, expires_at, csrf_token) VALUES ($1, $2, $3, $4)",
|
||||||
session.ID, session.Username, session.ExpiresAt, session.CSRFToken,
|
session.ID, session.Username, session.ExpiresAt, session.CSRFToken,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -79,7 +79,7 @@ func CreateSession(ctx context.Context, conn *pgxpool.Pool, username string) (*m
|
||||||
// Deletes a session by id. If no session with that id exists, no
|
// Deletes a session by id. If no session with that id exists, no
|
||||||
// error is returned.
|
// error is returned.
|
||||||
func DeleteSession(ctx context.Context, conn *pgxpool.Pool, id string) error {
|
func DeleteSession(ctx context.Context, conn *pgxpool.Pool, id string) error {
|
||||||
_, err := conn.Exec(ctx, "DELETE FROM sessions WHERE id = $1", id)
|
_, err := conn.Exec(ctx, "DELETE FROM session WHERE id = $1", id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return oops.New(err, "failed to delete session")
|
return oops.New(err, "failed to delete session")
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func DeleteSession(ctx context.Context, conn *pgxpool.Pool, id string) error {
|
||||||
func DeleteSessionForUser(ctx context.Context, conn *pgxpool.Pool, username string) error {
|
func DeleteSessionForUser(ctx context.Context, conn *pgxpool.Pool, username string) error {
|
||||||
_, err := conn.Exec(ctx,
|
_, err := conn.Exec(ctx,
|
||||||
`
|
`
|
||||||
DELETE FROM sessions
|
DELETE FROM session
|
||||||
WHERE LOWER(username) = LOWER($1)
|
WHERE LOWER(username) = LOWER($1)
|
||||||
`,
|
`,
|
||||||
username,
|
username,
|
||||||
|
@ -124,7 +124,7 @@ var DeleteSessionCookie = &http.Cookie{
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteExpiredSessions(ctx context.Context, conn *pgxpool.Pool) (int64, error) {
|
func DeleteExpiredSessions(ctx context.Context, conn *pgxpool.Pool) (int64, error) {
|
||||||
tag, err := conn.Exec(ctx, "DELETE FROM sessions WHERE expires_at <= CURRENT_TIMESTAMP")
|
tag, err := conn.Exec(ctx, "DELETE FROM session WHERE expires_at <= CURRENT_TIMESTAMP")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, oops.New(err, "failed to delete expired sessions")
|
return 0, oops.New(err, "failed to delete expired sessions")
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
|
|
||||||
var Config = HMNConfig{
|
var Config = HMNConfig{
|
||||||
Env: Dev,
|
Env: Dev,
|
||||||
Addr: ":9001",
|
Addr: "localhost:9001",
|
||||||
PrivateAddr: ":9002",
|
PrivateAddr: "localhost:9002",
|
||||||
BaseUrl: "http://handmade.local:9001",
|
BaseUrl: "http://handmade.local:9001",
|
||||||
LogLevel: zerolog.TraceLevel, // InfoLevel is recommended for production
|
LogLevel: zerolog.TraceLevel, // InfoLevel is recommended for production
|
||||||
Postgres: PostgresConfig{
|
Postgres: PostgresConfig{
|
||||||
|
|
|
@ -12,7 +12,7 @@ Arguments can be provided using placeholders like $1, $2, etc. All arguments wil
|
||||||
projectIDs, err := db.Query[int](ctx, conn,
|
projectIDs, err := db.Query[int](ctx, conn,
|
||||||
`
|
`
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM handmade_project
|
FROM project
|
||||||
WHERE
|
WHERE
|
||||||
slug = ANY($1)
|
slug = ANY($1)
|
||||||
AND hidden = $2
|
AND hidden = $2
|
||||||
|
@ -25,7 +25,7 @@ Arguments can be provided using placeholders like $1, $2, etc. All arguments wil
|
||||||
|
|
||||||
When querying individual fields, you can simply select the field like so:
|
When querying individual fields, you can simply select the field like so:
|
||||||
|
|
||||||
ids, err := db.Query[int](ctx, conn, `SELECT id FROM handmade_project`)
|
ids, err := db.Query[int](ctx, conn, `SELECT id FROM project`)
|
||||||
|
|
||||||
To query multiple columns at once, you may use a struct type with `db:"column_name"` tags, and the special $columns placeholder:
|
To query multiple columns at once, you may use a struct type with `db:"column_name"` tags, and the special $columns placeholder:
|
||||||
|
|
||||||
|
@ -48,8 +48,8 @@ Sometimes a table name prefix is required on each column to disambiguate between
|
||||||
orphanedProjects, err := db.Query[Project](ctx, conn, `
|
orphanedProjects, err := db.Query[Project](ctx, conn, `
|
||||||
SELECT $columns{projects}
|
SELECT $columns{projects}
|
||||||
FROM
|
FROM
|
||||||
handmade_project AS projects
|
project AS projects
|
||||||
LEFT JOIN handmade_user_projects AS uproj
|
LEFT JOIN user_project AS uproj
|
||||||
WHERE
|
WHERE
|
||||||
uproj.user_id IS NULL
|
uproj.user_id IS NULL
|
||||||
`)
|
`)
|
||||||
|
|
|
@ -92,11 +92,11 @@ func (bot *botInstance) handleProfileCommand(ctx context.Context, i *Interaction
|
||||||
|
|
||||||
hmnUser, err := db.QueryOne[models.User](ctx, bot.dbConn,
|
hmnUser, err := db.QueryOne[models.User](ctx, bot.dbConn,
|
||||||
`
|
`
|
||||||
SELECT $columns{auth_user}
|
SELECT $columns{hmn_user}
|
||||||
FROM
|
FROM
|
||||||
handmade_discorduser AS duser
|
discord_user AS duser
|
||||||
JOIN auth_user ON duser.hmn_user_id = auth_user.id
|
JOIN hmn_user ON duser.hmn_user_id = hmn_user.id
|
||||||
LEFT JOIN handmade_asset AS auth_user_avatar ON auth_user_avatar.id = auth_user.avatar_asset_id
|
LEFT JOIN asset AS hmn_user_avatar ON hmn_user_avatar.id = hmn_user.avatar_asset_id
|
||||||
WHERE
|
WHERE
|
||||||
duser.userid = $1
|
duser.userid = $1
|
||||||
`,
|
`,
|
||||||
|
|
|
@ -408,7 +408,7 @@ func (bot *botInstance) doSender(ctx context.Context) {
|
||||||
|
|
||||||
msgs, err := db.Query[models.DiscordOutgoingMessage](ctx, tx, `
|
msgs, err := db.Query[models.DiscordOutgoingMessage](ctx, tx, `
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM discord_outgoingmessages
|
FROM discord_outgoing_message
|
||||||
ORDER BY id ASC
|
ORDER BY id ASC
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -430,7 +430,7 @@ func (bot *botInstance) doSender(ctx context.Context) {
|
||||||
|
|
||||||
https://www.postgresql.org/docs/current/transaction-iso.html
|
https://www.postgresql.org/docs/current/transaction-iso.html
|
||||||
*/
|
*/
|
||||||
_, err = tx.Exec(ctx, `DELETE FROM discord_outgoingmessages`)
|
_, err = tx.Exec(ctx, `DELETE FROM discord_outgoing_message`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to delete outgoing messages")
|
log.Error().Err(err).Msg("failed to delete outgoing messages")
|
||||||
return
|
return
|
||||||
|
@ -644,7 +644,7 @@ func SendMessages(
|
||||||
|
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO discord_outgoingmessages (channel_id, payload_json, expires_at)
|
INSERT INTO discord_outgoing_message (channel_id, payload_json, expires_at)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
`,
|
`,
|
||||||
msg.ChannelID,
|
msg.ChannelID,
|
||||||
|
|
|
@ -77,9 +77,9 @@ func fetchMissingContent(ctx context.Context, dbConn *pgxpool.Pool) {
|
||||||
`
|
`
|
||||||
SELECT $columns{msg}
|
SELECT $columns{msg}
|
||||||
FROM
|
FROM
|
||||||
handmade_discordmessage AS msg
|
discord_message AS msg
|
||||||
JOIN handmade_discorduser AS duser ON msg.user_id = duser.userid -- only fetch messages for linked discord users
|
JOIN discord_user AS duser ON msg.user_id = duser.userid -- only fetch messages for linked discord users
|
||||||
LEFT JOIN handmade_discordmessagecontent AS c ON c.message_id = msg.id
|
LEFT JOIN discord_message_content AS c ON c.message_id = msg.id
|
||||||
WHERE
|
WHERE
|
||||||
c.last_content IS NULL
|
c.last_content IS NULL
|
||||||
AND msg.guild_id = $1
|
AND msg.guild_id = $1
|
||||||
|
|
|
@ -168,7 +168,7 @@ func InternMessage(
|
||||||
_, err := db.QueryOne[models.DiscordMessage](ctx, dbConn,
|
_, err := db.QueryOne[models.DiscordMessage](ctx, dbConn,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_discordmessage
|
FROM discord_message
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
msg.ID,
|
msg.ID,
|
||||||
|
@ -190,7 +190,7 @@ func InternMessage(
|
||||||
|
|
||||||
_, err = dbConn.Exec(ctx,
|
_, err = dbConn.Exec(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_discordmessage (id, channel_id, guild_id, url, user_id, sent_at, snippet_created)
|
INSERT INTO discord_message (id, channel_id, guild_id, url, user_id, sent_at, snippet_created)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
`,
|
`,
|
||||||
msg.ID,
|
msg.ID,
|
||||||
|
@ -223,11 +223,11 @@ func FetchInternedMessage(ctx context.Context, dbConn db.ConnOrTx, msgId string)
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_discordmessage AS message
|
discord_message AS message
|
||||||
LEFT JOIN handmade_discordmessagecontent AS content ON content.message_id = message.id
|
LEFT JOIN discord_message_content AS content ON content.message_id = message.id
|
||||||
LEFT JOIN handmade_discorduser AS duser ON duser.userid = message.user_id
|
LEFT JOIN discord_user AS duser ON duser.userid = message.user_id
|
||||||
LEFT JOIN auth_user AS hmnuser ON hmnuser.id = duser.hmn_user_id
|
LEFT JOIN hmn_user AS hmnuser ON hmnuser.id = duser.hmn_user_id
|
||||||
LEFT JOIN handmade_asset AS hmnuser_avatar ON hmnuser_avatar.id = hmnuser.avatar_asset_id
|
LEFT JOIN asset AS hmnuser_avatar ON hmnuser_avatar.id = hmnuser.avatar_asset_id
|
||||||
WHERE message.id = $1
|
WHERE message.id = $1
|
||||||
`,
|
`,
|
||||||
msgId,
|
msgId,
|
||||||
|
@ -284,7 +284,7 @@ func DeleteInternedMessage(ctx context.Context, dbConn db.ConnOrTx, interned *In
|
||||||
snippet, err := db.QueryOne[models.Snippet](ctx, dbConn,
|
snippet, err := db.QueryOne[models.Snippet](ctx, dbConn,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_snippet
|
FROM snippet
|
||||||
WHERE discord_message_id = $1
|
WHERE discord_message_id = $1
|
||||||
`,
|
`,
|
||||||
interned.Message.ID,
|
interned.Message.ID,
|
||||||
|
@ -294,13 +294,13 @@ func DeleteInternedMessage(ctx context.Context, dbConn db.ConnOrTx, interned *In
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(asaf): Also deletes the following through a db cascade:
|
// NOTE(asaf): Also deletes the following through a db cascade:
|
||||||
// * handmade_discordmessageattachment
|
// * discord_message_attachment
|
||||||
// * handmade_discordmessagecontent
|
// * discord_message_content
|
||||||
// * handmade_discordmessageembed
|
// * discord_message_embed
|
||||||
// DOES NOT DELETE ASSETS FOR CONTENT/EMBEDS
|
// DOES NOT DELETE ASSETS FOR CONTENT/EMBEDS
|
||||||
_, err = dbConn.Exec(ctx,
|
_, err = dbConn.Exec(ctx,
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_discordmessage
|
DELETE FROM discord_message
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
interned.Message.ID,
|
interned.Message.ID,
|
||||||
|
@ -312,7 +312,7 @@ func DeleteInternedMessage(ctx context.Context, dbConn db.ConnOrTx, interned *In
|
||||||
// NOTE(asaf): Does not delete asset!
|
// NOTE(asaf): Does not delete asset!
|
||||||
_, err = dbConn.Exec(ctx,
|
_, err = dbConn.Exec(ctx,
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_snippet
|
DELETE FROM snippet
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
snippet.ID,
|
snippet.ID,
|
||||||
|
@ -347,7 +347,7 @@ func SaveMessageContents(
|
||||||
if msg.OriginalHasFields("content") {
|
if msg.OriginalHasFields("content") {
|
||||||
_, err := dbConn.Exec(ctx,
|
_, err := dbConn.Exec(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_discordmessagecontent (message_id, discord_id, last_content)
|
INSERT INTO discord_message_content (message_id, discord_id, last_content)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
ON CONFLICT (message_id) DO UPDATE SET
|
ON CONFLICT (message_id) DO UPDATE SET
|
||||||
discord_id = EXCLUDED.discord_id,
|
discord_id = EXCLUDED.discord_id,
|
||||||
|
@ -365,9 +365,9 @@ func SaveMessageContents(
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_discordmessagecontent
|
discord_message_content
|
||||||
WHERE
|
WHERE
|
||||||
handmade_discordmessagecontent.message_id = $1
|
discord_message_content.message_id = $1
|
||||||
`,
|
`,
|
||||||
interned.Message.ID,
|
interned.Message.ID,
|
||||||
)
|
)
|
||||||
|
@ -392,7 +392,7 @@ func SaveMessageContents(
|
||||||
numSavedEmbeds, err := db.QueryOneScalar[int](ctx, dbConn,
|
numSavedEmbeds, err := db.QueryOneScalar[int](ctx, dbConn,
|
||||||
`
|
`
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM handmade_discordmessageembed
|
FROM discord_message_embed
|
||||||
WHERE message_id = $1
|
WHERE message_id = $1
|
||||||
`,
|
`,
|
||||||
msg.ID,
|
msg.ID,
|
||||||
|
@ -412,7 +412,7 @@ func SaveMessageContents(
|
||||||
// Embeds were removed from the message
|
// Embeds were removed from the message
|
||||||
_, err := dbConn.Exec(ctx,
|
_, err := dbConn.Exec(ctx,
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_discordmessageembed
|
DELETE FROM discord_message_embed
|
||||||
WHERE message_id = $1
|
WHERE message_id = $1
|
||||||
`,
|
`,
|
||||||
msg.ID,
|
msg.ID,
|
||||||
|
@ -469,7 +469,7 @@ func saveAttachment(
|
||||||
existing, err := db.QueryOne[models.DiscordMessageAttachment](ctx, tx,
|
existing, err := db.QueryOne[models.DiscordMessageAttachment](ctx, tx,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_discordmessageattachment
|
FROM discord_message_attachment
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
attachment.ID,
|
attachment.ID,
|
||||||
|
@ -517,7 +517,7 @@ func saveAttachment(
|
||||||
// TODO(db): RETURNING plz thanks
|
// TODO(db): RETURNING plz thanks
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_discordmessageattachment (id, asset_id, message_id)
|
INSERT INTO discord_message_attachment (id, asset_id, message_id)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
`,
|
`,
|
||||||
attachment.ID,
|
attachment.ID,
|
||||||
|
@ -531,7 +531,7 @@ func saveAttachment(
|
||||||
discordAttachment, err := db.QueryOne[models.DiscordMessageAttachment](ctx, tx,
|
discordAttachment, err := db.QueryOne[models.DiscordMessageAttachment](ctx, tx,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_discordmessageattachment
|
FROM discord_message_attachment
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
attachment.ID,
|
attachment.ID,
|
||||||
|
@ -615,7 +615,7 @@ func saveEmbed(
|
||||||
var savedEmbedId int
|
var savedEmbedId int
|
||||||
err = tx.QueryRow(ctx,
|
err = tx.QueryRow(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_discordmessageembed (title, description, url, message_id, image_id, video_id)
|
INSERT INTO discord_message_embed (title, description, url, message_id, image_id, video_id)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`,
|
`,
|
||||||
|
@ -633,7 +633,7 @@ func saveEmbed(
|
||||||
discordEmbed, err := db.QueryOne[models.DiscordMessageEmbed](ctx, tx,
|
discordEmbed, err := db.QueryOne[models.DiscordMessageEmbed](ctx, tx,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_discordmessageembed
|
FROM discord_message_embed
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
savedEmbedId,
|
savedEmbedId,
|
||||||
|
@ -649,7 +649,7 @@ func FetchSnippetForMessage(ctx context.Context, dbConn db.ConnOrTx, msgID strin
|
||||||
snippet, err := db.QueryOne[models.Snippet](ctx, dbConn,
|
snippet, err := db.QueryOne[models.Snippet](ctx, dbConn,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_snippet
|
FROM snippet
|
||||||
WHERE discord_message_id = $1
|
WHERE discord_message_id = $1
|
||||||
`,
|
`,
|
||||||
msgID,
|
msgID,
|
||||||
|
@ -712,7 +712,7 @@ func HandleSnippetForInternedMessage(ctx context.Context, dbConn db.ConnOrTx, in
|
||||||
|
|
||||||
_, err := tx.Exec(ctx,
|
_, err := tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_snippet
|
UPDATE snippet
|
||||||
SET
|
SET
|
||||||
description = $1,
|
description = $1,
|
||||||
_description_html = $2
|
_description_html = $2
|
||||||
|
@ -741,7 +741,7 @@ func HandleSnippetForInternedMessage(ctx context.Context, dbConn db.ConnOrTx, in
|
||||||
|
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_snippet (url, "when", description, _description_html, asset_id, discord_message_id, owner_id)
|
INSERT INTO snippet (url, "when", description, _description_html, asset_id, discord_message_id, owner_id)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
`,
|
`,
|
||||||
url,
|
url,
|
||||||
|
@ -763,7 +763,7 @@ func HandleSnippetForInternedMessage(ctx context.Context, dbConn db.ConnOrTx, in
|
||||||
|
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_discordmessage
|
UPDATE discord_message
|
||||||
SET snippet_created = TRUE
|
SET snippet_created = TRUE
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
|
@ -801,10 +801,10 @@ func HandleSnippetForInternedMessage(ctx context.Context, dbConn db.ConnOrTx, in
|
||||||
|
|
||||||
userTags, err := db.Query[models.Tag](ctx, tx,
|
userTags, err := db.Query[models.Tag](ctx, tx,
|
||||||
`
|
`
|
||||||
SELECT $columns{tags}
|
SELECT $columns{tag}
|
||||||
FROM
|
FROM
|
||||||
tags
|
tags
|
||||||
JOIN handmade_project AS project ON project.tag = tags.id
|
JOIN project ON project.tag = tag.id
|
||||||
WHERE
|
WHERE
|
||||||
project.id = ANY ($1)
|
project.id = ANY ($1)
|
||||||
`,
|
`,
|
||||||
|
@ -825,7 +825,7 @@ func HandleSnippetForInternedMessage(ctx context.Context, dbConn db.ConnOrTx, in
|
||||||
|
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
DELETE FROM snippet_tags
|
DELETE FROM snippet_tag
|
||||||
WHERE
|
WHERE
|
||||||
snippet_id = $1
|
snippet_id = $1
|
||||||
AND tag_id = ANY ($2)
|
AND tag_id = ANY ($2)
|
||||||
|
@ -840,7 +840,7 @@ func HandleSnippetForInternedMessage(ctx context.Context, dbConn db.ConnOrTx, in
|
||||||
for _, tagID := range desiredTags {
|
for _, tagID := range desiredTags {
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO snippet_tags (snippet_id, tag_id)
|
INSERT INTO snippet_tag (snippet_id, tag_id)
|
||||||
VALUES ($1, $2)
|
VALUES ($1, $2)
|
||||||
ON CONFLICT DO NOTHING
|
ON CONFLICT DO NOTHING
|
||||||
`,
|
`,
|
||||||
|
@ -883,7 +883,7 @@ func getSnippetAssetOrUrl(ctx context.Context, tx db.ConnOrTx, msg *models.Disco
|
||||||
attachments, err := db.Query[models.DiscordMessageAttachment](ctx, tx,
|
attachments, err := db.Query[models.DiscordMessageAttachment](ctx, tx,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_discordmessageattachment
|
FROM discord_message_attachment
|
||||||
WHERE message_id = $1
|
WHERE message_id = $1
|
||||||
`,
|
`,
|
||||||
msg.ID,
|
msg.ID,
|
||||||
|
@ -899,7 +899,7 @@ func getSnippetAssetOrUrl(ctx context.Context, tx db.ConnOrTx, msg *models.Disco
|
||||||
embeds, err := db.Query[models.DiscordMessageEmbed](ctx, tx,
|
embeds, err := db.Query[models.DiscordMessageEmbed](ctx, tx,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_discordmessageembed
|
FROM discord_message_embed
|
||||||
WHERE message_id = $1
|
WHERE message_id = $1
|
||||||
`,
|
`,
|
||||||
msg.ID,
|
msg.ID,
|
||||||
|
|
|
@ -71,7 +71,7 @@ func FetchProjects(
|
||||||
Project models.Project `db:"project"`
|
Project models.Project `db:"project"`
|
||||||
LogoLightAsset *models.Asset `db:"logolight_asset"`
|
LogoLightAsset *models.Asset `db:"logolight_asset"`
|
||||||
LogoDarkAsset *models.Asset `db:"logodark_asset"`
|
LogoDarkAsset *models.Asset `db:"logodark_asset"`
|
||||||
Tag *models.Tag `db:"tags"`
|
Tag *models.Tag `db:"tag"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch all valid projects (not yet subject to user permission checks)
|
// Fetch all valid projects (not yet subject to user permission checks)
|
||||||
|
@ -82,17 +82,17 @@ func FetchProjects(
|
||||||
qb.Add(`
|
qb.Add(`
|
||||||
SELECT DISTINCT ON (project.id) $columns
|
SELECT DISTINCT ON (project.id) $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_project AS project
|
project
|
||||||
LEFT JOIN handmade_asset AS logolight_asset ON logolight_asset.id = project.logolight_asset_id
|
LEFT JOIN asset AS logolight_asset ON logolight_asset.id = project.logolight_asset_id
|
||||||
LEFT JOIN handmade_asset AS logodark_asset ON logodark_asset.id = project.logodark_asset_id
|
LEFT JOIN asset AS logodark_asset ON logodark_asset.id = project.logodark_asset_id
|
||||||
LEFT JOIN tags ON project.tag = tags.id
|
LEFT JOIN tag ON project.tag = tag.id
|
||||||
`)
|
`)
|
||||||
if len(q.OwnerIDs) > 0 {
|
if len(q.OwnerIDs) > 0 {
|
||||||
qb.Add(
|
qb.Add(
|
||||||
`
|
`
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT project_id, array_agg(user_id) AS owner_ids
|
SELECT project_id, array_agg(user_id) AS owner_ids
|
||||||
FROM handmade_user_projects
|
FROM user_project
|
||||||
WHERE user_id = ANY ($?)
|
WHERE user_id = ANY ($?)
|
||||||
GROUP BY project_id
|
GROUP BY project_id
|
||||||
) AS owner_filter ON project.id = owner_filter.project_id
|
) AS owner_filter ON project.id = owner_filter.project_id
|
||||||
|
@ -336,7 +336,7 @@ func FetchMultipleProjectsOwners(
|
||||||
userProjects, err := db.Query[userProject](ctx, tx,
|
userProjects, err := db.Query[userProject](ctx, tx,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_user_projects
|
FROM user_project
|
||||||
WHERE project_id = ANY($1)
|
WHERE project_id = ANY($1)
|
||||||
`,
|
`,
|
||||||
projectIds,
|
projectIds,
|
||||||
|
@ -360,12 +360,12 @@ func FetchMultipleProjectsOwners(
|
||||||
}
|
}
|
||||||
users, err := db.Query[models.User](ctx, tx,
|
users, err := db.Query[models.User](ctx, tx,
|
||||||
`
|
`
|
||||||
SELECT $columns{auth_user}
|
SELECT $columns{hmn_user}
|
||||||
FROM
|
FROM
|
||||||
auth_user
|
hmn_user
|
||||||
LEFT JOIN handmade_asset AS auth_user_avatar ON auth_user_avatar.id = auth_user.avatar_asset_id
|
LEFT JOIN asset AS hmn_user_avatar ON hmn_user_avatar.id = hmn_user.avatar_asset_id
|
||||||
WHERE
|
WHERE
|
||||||
auth_user.id = ANY($1)
|
hmn_user.id = ANY($1)
|
||||||
`,
|
`,
|
||||||
userIds,
|
userIds,
|
||||||
)
|
)
|
||||||
|
@ -467,7 +467,7 @@ func SetProjectTag(
|
||||||
// Create a tag
|
// Create a tag
|
||||||
tag, err := db.QueryOne[models.Tag](ctx, tx,
|
tag, err := db.QueryOne[models.Tag](ctx, tx,
|
||||||
`
|
`
|
||||||
INSERT INTO tags (text) VALUES ($1)
|
INSERT INTO tag (text) VALUES ($1)
|
||||||
RETURNING $columns
|
RETURNING $columns
|
||||||
`,
|
`,
|
||||||
tagText,
|
tagText,
|
||||||
|
@ -480,7 +480,7 @@ func SetProjectTag(
|
||||||
// Attach it to the project
|
// Attach it to the project
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_project
|
UPDATE project
|
||||||
SET tag = $1
|
SET tag = $1
|
||||||
WHERE id = $2
|
WHERE id = $2
|
||||||
`,
|
`,
|
||||||
|
@ -493,9 +493,9 @@ func SetProjectTag(
|
||||||
// Update the text of an existing one
|
// Update the text of an existing one
|
||||||
tag, err := db.QueryOne[models.Tag](ctx, tx,
|
tag, err := db.QueryOne[models.Tag](ctx, tx,
|
||||||
`
|
`
|
||||||
UPDATE tags
|
UPDATE tag
|
||||||
SET text = $1
|
SET text = $1
|
||||||
WHERE id = (SELECT tag FROM handmade_project WHERE id = $2)
|
WHERE id = (SELECT tag FROM project WHERE id = $2)
|
||||||
RETURNING $columns
|
RETURNING $columns
|
||||||
`,
|
`,
|
||||||
tagText, projectID,
|
tagText, projectID,
|
||||||
|
|
|
@ -48,10 +48,10 @@ func FetchSnippets(
|
||||||
`
|
`
|
||||||
SELECT DISTINCT snippet_id
|
SELECT DISTINCT snippet_id
|
||||||
FROM
|
FROM
|
||||||
snippet_tags
|
snippet_tag
|
||||||
JOIN tags ON snippet_tags.tag_id = tags.id
|
JOIN tag ON snippet_tag.tag_id = tag.id
|
||||||
WHERE
|
WHERE
|
||||||
tags.id = ANY ($1)
|
tag.id = ANY ($1)
|
||||||
`,
|
`,
|
||||||
q.Tags,
|
q.Tags,
|
||||||
)
|
)
|
||||||
|
@ -72,11 +72,11 @@ func FetchSnippets(
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_snippet AS snippet
|
snippet
|
||||||
LEFT JOIN auth_user AS owner ON snippet.owner_id = owner.id
|
LEFT JOIN hmn_user AS owner ON snippet.owner_id = owner.id
|
||||||
LEFT JOIN handmade_asset AS owner_avatar ON owner_avatar.id = owner.avatar_asset_id
|
LEFT JOIN asset AS owner_avatar ON owner_avatar.id = owner.avatar_asset_id
|
||||||
LEFT JOIN handmade_asset AS asset ON snippet.asset_id = asset.id
|
LEFT JOIN asset ON snippet.asset_id = asset.id
|
||||||
LEFT JOIN handmade_discordmessage AS discord_message ON snippet.discord_message_id = discord_message.id
|
LEFT JOIN discord_message ON snippet.discord_message_id = discord_message.id
|
||||||
WHERE
|
WHERE
|
||||||
TRUE
|
TRUE
|
||||||
`,
|
`,
|
||||||
|
@ -139,17 +139,17 @@ func FetchSnippets(
|
||||||
|
|
||||||
// Fetch tags
|
// Fetch tags
|
||||||
type snippetTagRow struct {
|
type snippetTagRow struct {
|
||||||
SnippetID int `db:"snippet_tags.snippet_id"`
|
SnippetID int `db:"snippet_tag.snippet_id"`
|
||||||
Tag *models.Tag `db:"tags"`
|
Tag *models.Tag `db:"tag"`
|
||||||
}
|
}
|
||||||
snippetTags, err := db.Query[snippetTagRow](ctx, tx,
|
snippetTags, err := db.Query[snippetTagRow](ctx, tx,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
snippet_tags
|
snippet_tag
|
||||||
JOIN tags ON snippet_tags.tag_id = tags.id
|
JOIN tag ON snippet_tag.tag_id = tag.id
|
||||||
WHERE
|
WHERE
|
||||||
snippet_tags.snippet_id = ANY($1)
|
snippet_tag.snippet_id = ANY($1)
|
||||||
`,
|
`,
|
||||||
snippetIDs,
|
snippetIDs,
|
||||||
)
|
)
|
||||||
|
|
|
@ -25,7 +25,7 @@ func FetchTags(ctx context.Context, dbConn db.ConnOrTx, q TagQuery) ([]*models.T
|
||||||
qb.Add(
|
qb.Add(
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM tags
|
FROM tag
|
||||||
WHERE
|
WHERE
|
||||||
TRUE
|
TRUE
|
||||||
`,
|
`,
|
||||||
|
|
|
@ -71,21 +71,21 @@ func FetchThreads(
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_thread AS thread
|
thread
|
||||||
JOIN handmade_project AS project ON thread.project_id = project.id
|
JOIN project ON thread.project_id = project.id
|
||||||
JOIN handmade_post AS first_post ON first_post.id = thread.first_id
|
JOIN post AS first_post ON first_post.id = thread.first_id
|
||||||
JOIN handmade_post AS last_post ON last_post.id = thread.last_id
|
JOIN post AS last_post ON last_post.id = thread.last_id
|
||||||
JOIN handmade_postversion AS first_version ON first_version.id = first_post.current_id
|
JOIN post_version AS first_version ON first_version.id = first_post.current_id
|
||||||
JOIN handmade_postversion AS last_version ON last_version.id = last_post.current_id
|
JOIN post_version AS last_version ON last_version.id = last_post.current_id
|
||||||
LEFT JOIN auth_user AS first_author ON first_author.id = first_post.author_id
|
LEFT JOIN hmn_user AS first_author ON first_author.id = first_post.author_id
|
||||||
LEFT JOIN handmade_asset AS first_author_avatar ON first_author_avatar.id = first_author.avatar_asset_id
|
LEFT JOIN asset AS first_author_avatar ON first_author_avatar.id = first_author.avatar_asset_id
|
||||||
LEFT JOIN auth_user AS last_author ON last_author.id = last_post.author_id
|
LEFT JOIN hmn_user AS last_author ON last_author.id = last_post.author_id
|
||||||
LEFT JOIN handmade_asset AS last_author_avatar ON last_author_avatar.id = last_author.avatar_asset_id
|
LEFT JOIN asset AS last_author_avatar ON last_author_avatar.id = last_author.avatar_asset_id
|
||||||
LEFT JOIN handmade_threadlastreadinfo AS tlri ON (
|
LEFT JOIN thread_last_read_info AS tlri ON (
|
||||||
tlri.thread_id = thread.id
|
tlri.thread_id = thread.id
|
||||||
AND tlri.user_id = $?
|
AND tlri.user_id = $?
|
||||||
)
|
)
|
||||||
LEFT JOIN handmade_subforumlastreadinfo AS slri ON (
|
LEFT JOIN subforum_last_read_info AS slri ON (
|
||||||
slri.subforum_id = thread.subforum_id
|
slri.subforum_id = thread.subforum_id
|
||||||
AND slri.user_id = $?
|
AND slri.user_id = $?
|
||||||
)
|
)
|
||||||
|
@ -219,11 +219,11 @@ func CountThreads(
|
||||||
`
|
`
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
handmade_thread AS thread
|
thread
|
||||||
JOIN handmade_project AS project ON thread.project_id = project.id
|
JOIN project ON thread.project_id = project.id
|
||||||
JOIN handmade_post AS first_post ON first_post.id = thread.first_id
|
JOIN post AS first_post ON first_post.id = thread.first_id
|
||||||
LEFT JOIN auth_user AS first_author ON first_author.id = first_post.author_id
|
LEFT JOIN hmn_user AS first_author ON first_author.id = first_post.author_id
|
||||||
LEFT JOIN handmade_asset AS first_author_avatar ON first_author_avatar.id = first_author.avatar_asset_id
|
LEFT JOIN asset AS first_author_avatar ON first_author_avatar.id = first_author.avatar_asset_id
|
||||||
WHERE
|
WHERE
|
||||||
NOT thread.deleted
|
NOT thread.deleted
|
||||||
AND ( -- project has valid lifecycle
|
AND ( -- project has valid lifecycle
|
||||||
|
@ -328,28 +328,28 @@ func FetchPosts(
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_post AS post
|
post
|
||||||
JOIN handmade_thread AS thread ON post.thread_id = thread.id
|
JOIN thread ON post.thread_id = thread.id
|
||||||
JOIN handmade_project AS project ON post.project_id = project.id
|
JOIN project ON post.project_id = project.id
|
||||||
JOIN handmade_postversion AS ver ON ver.id = post.current_id
|
JOIN post_version AS ver ON ver.id = post.current_id
|
||||||
LEFT JOIN auth_user AS author ON author.id = post.author_id
|
LEFT JOIN hmn_user AS author ON author.id = post.author_id
|
||||||
LEFT JOIN handmade_asset AS author_avatar ON author_avatar.id = author.avatar_asset_id
|
LEFT JOIN asset AS author_avatar ON author_avatar.id = author.avatar_asset_id
|
||||||
LEFT JOIN auth_user AS editor ON ver.editor_id = editor.id
|
LEFT JOIN hmn_user AS editor ON ver.editor_id = editor.id
|
||||||
LEFT JOIN handmade_asset AS editor_avatar ON editor_avatar.id = editor.avatar_asset_id
|
LEFT JOIN asset AS editor_avatar ON editor_avatar.id = editor.avatar_asset_id
|
||||||
LEFT JOIN handmade_threadlastreadinfo AS tlri ON (
|
LEFT JOIN thread_last_read_info AS tlri ON (
|
||||||
tlri.thread_id = thread.id
|
tlri.thread_id = thread.id
|
||||||
AND tlri.user_id = $?
|
AND tlri.user_id = $?
|
||||||
)
|
)
|
||||||
LEFT JOIN handmade_subforumlastreadinfo AS slri ON (
|
LEFT JOIN subforum_last_read_info AS slri ON (
|
||||||
slri.subforum_id = thread.subforum_id
|
slri.subforum_id = thread.subforum_id
|
||||||
AND slri.user_id = $?
|
AND slri.user_id = $?
|
||||||
)
|
)
|
||||||
-- Unconditionally fetch reply info, but make sure to check it
|
-- Unconditionally fetch reply info, but make sure to check it
|
||||||
-- later and possibly remove these fields if the permission
|
-- later and possibly remove these fields if the permission
|
||||||
-- check fails.
|
-- check fails.
|
||||||
LEFT JOIN handmade_post AS reply_post ON reply_post.id = post.reply_id
|
LEFT JOIN post AS reply_post ON reply_post.id = post.reply_id
|
||||||
LEFT JOIN auth_user AS reply_author ON reply_post.author_id = reply_author.id
|
LEFT JOIN hmn_user AS reply_author ON reply_post.author_id = reply_author.id
|
||||||
LEFT JOIN handmade_asset AS reply_author_avatar ON reply_author_avatar.id = reply_author.avatar_asset_id
|
LEFT JOIN asset AS reply_author_avatar ON reply_author_avatar.id = reply_author.avatar_asset_id
|
||||||
WHERE
|
WHERE
|
||||||
NOT thread.deleted
|
NOT thread.deleted
|
||||||
AND NOT post.deleted
|
AND NOT post.deleted
|
||||||
|
@ -545,11 +545,11 @@ func CountPosts(
|
||||||
`
|
`
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
handmade_post AS post
|
post
|
||||||
JOIN handmade_thread AS thread ON post.thread_id = thread.id
|
JOIN thread ON post.thread_id = thread.id
|
||||||
JOIN handmade_project AS project ON post.project_id = project.id
|
JOIN project ON post.project_id = project.id
|
||||||
LEFT JOIN auth_user AS author ON author.id = post.author_id
|
LEFT JOIN hmn_user AS author ON author.id = post.author_id
|
||||||
LEFT JOIN handmade_asset AS author_avatar ON author_avatar.id = author.avatar_asset_id
|
LEFT JOIN asset AS author_avatar ON author_avatar.id = author.avatar_asset_id
|
||||||
WHERE
|
WHERE
|
||||||
NOT thread.deleted
|
NOT thread.deleted
|
||||||
AND NOT post.deleted
|
AND NOT post.deleted
|
||||||
|
@ -608,7 +608,7 @@ func UserCanEditPost(ctx context.Context, connOrTx db.ConnOrTx, user models.User
|
||||||
`
|
`
|
||||||
SELECT post.author_id
|
SELECT post.author_id
|
||||||
FROM
|
FROM
|
||||||
handmade_post AS post
|
post
|
||||||
WHERE
|
WHERE
|
||||||
post.id = $1
|
post.id = $1
|
||||||
AND NOT post.deleted
|
AND NOT post.deleted
|
||||||
|
@ -639,7 +639,7 @@ func CreateNewPost(
|
||||||
// Create post
|
// Create post
|
||||||
err := tx.QueryRow(ctx,
|
err := tx.QueryRow(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_post (postdate, thread_id, thread_type, current_id, author_id, project_id, reply_id, preview)
|
INSERT INTO post (postdate, thread_id, thread_type, current_id, author_id, project_id, reply_id, preview)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`,
|
`,
|
||||||
|
@ -680,7 +680,7 @@ func CreateNewPost(
|
||||||
|
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_project
|
UPDATE project
|
||||||
SET `+updates+`
|
SET `+updates+`
|
||||||
WHERE
|
WHERE
|
||||||
id = $1
|
id = $1
|
||||||
|
@ -705,7 +705,7 @@ func DeletePost(
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_thread AS thread
|
thread
|
||||||
WHERE
|
WHERE
|
||||||
thread.id = $1
|
thread.id = $1
|
||||||
`,
|
`,
|
||||||
|
@ -723,7 +723,7 @@ func DeletePost(
|
||||||
// Just delete the whole thread and all its posts.
|
// Just delete the whole thread and all its posts.
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_thread
|
UPDATE thread
|
||||||
SET deleted = TRUE
|
SET deleted = TRUE
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
|
@ -731,7 +731,7 @@ func DeletePost(
|
||||||
)
|
)
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_post
|
UPDATE post
|
||||||
SET deleted = TRUE
|
SET deleted = TRUE
|
||||||
WHERE thread_id = $1
|
WHERE thread_id = $1
|
||||||
`,
|
`,
|
||||||
|
@ -743,7 +743,7 @@ func DeletePost(
|
||||||
|
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_post
|
UPDATE post
|
||||||
SET deleted = TRUE
|
SET deleted = TRUE
|
||||||
WHERE
|
WHERE
|
||||||
id = $1
|
id = $1
|
||||||
|
@ -789,7 +789,7 @@ func CreatePostVersion(ctx context.Context, tx pgx.Tx, postId int, unparsedConte
|
||||||
// Create post version
|
// Create post version
|
||||||
err := tx.QueryRow(ctx,
|
err := tx.QueryRow(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_postversion (post_id, text_raw, text_parsed, ip, date, edit_reason, editor_id)
|
INSERT INTO post_version (post_id, text_raw, text_parsed, ip, date, edit_reason, editor_id)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`,
|
`,
|
||||||
|
@ -808,7 +808,7 @@ func CreatePostVersion(ctx context.Context, tx pgx.Tx, postId int, unparsedConte
|
||||||
// Update post with version id and preview
|
// Update post with version id and preview
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_post
|
UPDATE post
|
||||||
SET current_id = $1, preview = $2
|
SET current_id = $1, preview = $2
|
||||||
WHERE id = $3
|
WHERE id = $3
|
||||||
`,
|
`,
|
||||||
|
@ -824,7 +824,7 @@ func CreatePostVersion(ctx context.Context, tx pgx.Tx, postId int, unparsedConte
|
||||||
|
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_post_asset_usage
|
DELETE FROM post_asset_usage
|
||||||
WHERE post_id = $1
|
WHERE post_id = $1
|
||||||
`,
|
`,
|
||||||
postId,
|
postId,
|
||||||
|
@ -842,7 +842,7 @@ func CreatePostVersion(ctx context.Context, tx pgx.Tx, postId int, unparsedConte
|
||||||
assetIDs, err := db.QueryScalar[uuid.UUID](ctx, tx,
|
assetIDs, err := db.QueryScalar[uuid.UUID](ctx, tx,
|
||||||
`
|
`
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM handmade_asset
|
FROM asset
|
||||||
WHERE s3_key = ANY($1)
|
WHERE s3_key = ANY($1)
|
||||||
`,
|
`,
|
||||||
keys,
|
keys,
|
||||||
|
@ -857,7 +857,7 @@ func CreatePostVersion(ctx context.Context, tx pgx.Tx, postId int, unparsedConte
|
||||||
values = append(values, []interface{}{postId, assetID})
|
values = append(values, []interface{}{postId, assetID})
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.CopyFrom(ctx, pgx.Identifier{"handmade_post_asset_usage"}, []string{"post_id", "asset_id"}, pgx.CopyFromRows(values))
|
_, err = tx.CopyFrom(ctx, pgx.Identifier{"post_asset_usage"}, []string{"post_id", "asset_id"}, pgx.CopyFromRows(values))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(oops.New(err, "failed to insert post asset usage"))
|
panic(oops.New(err, "failed to insert post asset usage"))
|
||||||
}
|
}
|
||||||
|
@ -877,7 +877,7 @@ func FixThreadPostIds(ctx context.Context, tx pgx.Tx, threadId int) error {
|
||||||
posts, err := db.Query[models.Post](ctx, tx,
|
posts, err := db.Query[models.Post](ctx, tx,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_post
|
FROM post
|
||||||
WHERE
|
WHERE
|
||||||
thread_id = $1
|
thread_id = $1
|
||||||
AND NOT deleted
|
AND NOT deleted
|
||||||
|
@ -904,7 +904,7 @@ func FixThreadPostIds(ctx context.Context, tx pgx.Tx, threadId int) error {
|
||||||
|
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_thread
|
UPDATE thread
|
||||||
SET first_id = $1, last_id = $2
|
SET first_id = $1, last_id = $2
|
||||||
WHERE id = $3
|
WHERE id = $3
|
||||||
`,
|
`,
|
||||||
|
|
|
@ -26,15 +26,15 @@ func FetchTwitchStreamers(ctx context.Context, dbConn db.ConnOrTx) ([]TwitchStre
|
||||||
`
|
`
|
||||||
SELECT $columns{link}
|
SELECT $columns{link}
|
||||||
FROM
|
FROM
|
||||||
handmade_links AS link
|
link
|
||||||
LEFT JOIN auth_user AS link_owner ON link_owner.id = link.user_id
|
LEFT JOIN hmn_user AS link_owner ON link_owner.id = link.user_id
|
||||||
WHERE
|
WHERE
|
||||||
url ~* 'twitch\.tv/([^/]+)$' AND
|
url ~* 'twitch\.tv/([^/]+)$' AND
|
||||||
((link.user_id IS NOT NULL AND link_owner.status = $1) OR (link.project_id IS NOT NULL AND
|
((link.user_id IS NOT NULL AND link_owner.status = $1) OR (link.project_id IS NOT NULL AND
|
||||||
(SELECT COUNT(*)
|
(SELECT COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
handmade_user_projects AS hup
|
user_project AS hup
|
||||||
JOIN auth_user AS project_owner ON project_owner.id = hup.user_id
|
JOIN hmn_user AS project_owner ON project_owner.id = hup.user_id
|
||||||
WHERE
|
WHERE
|
||||||
hup.project_id = link.project_id AND
|
hup.project_id = link.project_id AND
|
||||||
project_owner.status != $1
|
project_owner.status != $1
|
||||||
|
@ -80,7 +80,7 @@ func FetchTwitchLoginsForUserOrProject(ctx context.Context, dbConn db.ConnOrTx,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_links AS link
|
link
|
||||||
WHERE
|
WHERE
|
||||||
url ~* 'twitch\.tv/([^/]+)$'
|
url ~* 'twitch\.tv/([^/]+)$'
|
||||||
AND ((user_id = $1 AND project_id IS NULL) OR (user_id IS NULL AND project_id = $2))
|
AND ((user_id = $1 AND project_id IS NULL) OR (user_id IS NULL AND project_id = $2))
|
||||||
|
|
|
@ -24,6 +24,11 @@ import (
|
||||||
var listMigrations bool
|
var listMigrations bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
dbCommand := &cobra.Command{
|
||||||
|
Use: "db",
|
||||||
|
Short: "Database-related commands",
|
||||||
|
}
|
||||||
|
|
||||||
migrateCommand := &cobra.Command{
|
migrateCommand := &cobra.Command{
|
||||||
Use: "migrate [target migration id]",
|
Use: "migrate [target migration id]",
|
||||||
Short: "Run database migrations",
|
Short: "Run database migrations",
|
||||||
|
@ -78,9 +83,10 @@ func init() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
website.WebsiteCommand.AddCommand(migrateCommand)
|
website.WebsiteCommand.AddCommand(dbCommand)
|
||||||
website.WebsiteCommand.AddCommand(makeMigrationCommand)
|
dbCommand.AddCommand(migrateCommand)
|
||||||
website.WebsiteCommand.AddCommand(seedFromFileCommand)
|
dbCommand.AddCommand(makeMigrationCommand)
|
||||||
|
dbCommand.AddCommand(seedFromFileCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSortedMigrationVersions() []types.MigrationVersion {
|
func getSortedMigrationVersions() []types.MigrationVersion {
|
||||||
|
|
|
@ -0,0 +1,146 @@
|
||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.handmade.network/hmn/hmn/src/migration/types"
|
||||||
|
"git.handmade.network/hmn/hmn/src/oops"
|
||||||
|
"github.com/jackc/pgx/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerMigration(RenameEverything{})
|
||||||
|
}
|
||||||
|
|
||||||
|
type RenameEverything struct{}
|
||||||
|
|
||||||
|
func (m RenameEverything) Version() types.MigrationVersion {
|
||||||
|
return types.MigrationVersion(time.Date(2022, 5, 6, 22, 17, 26, 0, time.UTC))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m RenameEverything) Name() string {
|
||||||
|
return "RenameEverything"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m RenameEverything) Description() string {
|
||||||
|
return "Rename all the tables, and remove the ones we no longer need"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m RenameEverything) Up(ctx context.Context, tx pgx.Tx) error {
|
||||||
|
// Drop unused tables
|
||||||
|
_, err := tx.Exec(ctx, `
|
||||||
|
DROP TABLE
|
||||||
|
auth_permission,
|
||||||
|
django_content_type,
|
||||||
|
django_migrations,
|
||||||
|
django_site,
|
||||||
|
handmade_blacklistemail,
|
||||||
|
handmade_blacklisthostname,
|
||||||
|
handmade_codelanguage,
|
||||||
|
handmade_communicationchoice,
|
||||||
|
handmade_communicationchoicelist,
|
||||||
|
handmade_communicationsubcategory,
|
||||||
|
handmade_communicationsubthread,
|
||||||
|
handmade_kunenathread,
|
||||||
|
handmade_license,
|
||||||
|
handmade_license_texts,
|
||||||
|
handmade_project_languages,
|
||||||
|
handmade_project_licenses
|
||||||
|
`)
|
||||||
|
if err != nil {
|
||||||
|
return oops.New(err, "failed to drop unused tables")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rename everything!!
|
||||||
|
_, err = tx.Exec(ctx, `
|
||||||
|
ALTER TABLE auth_user RENAME TO hmn_user;
|
||||||
|
ALTER TABLE discord_outgoingmessages RENAME TO discord_outgoing_message;
|
||||||
|
ALTER TABLE handmade_asset RENAME TO asset;
|
||||||
|
ALTER TABLE handmade_discordmessage RENAME TO discord_message;
|
||||||
|
ALTER TABLE handmade_discordmessageattachment RENAME TO discord_message_attachment;
|
||||||
|
ALTER TABLE handmade_discordmessagecontent RENAME TO discord_message_content;
|
||||||
|
ALTER TABLE handmade_discordmessageembed RENAME TO discord_message_embed;
|
||||||
|
ALTER TABLE handmade_discorduser RENAME TO discord_user;
|
||||||
|
ALTER TABLE handmade_imagefile RENAME TO image_file;
|
||||||
|
ALTER TABLE handmade_librarymediatype RENAME TO library_media_type;
|
||||||
|
ALTER TABLE handmade_libraryresource RENAME TO library_resource;
|
||||||
|
ALTER TABLE handmade_libraryresource_media_types RENAME TO library_resource_media_type;
|
||||||
|
ALTER TABLE handmade_libraryresource_topics RENAME TO library_resource_topic;
|
||||||
|
ALTER TABLE handmade_libraryresourcestar RENAME TO library_resource_star;
|
||||||
|
ALTER TABLE handmade_librarytopic RENAME TO library_topic;
|
||||||
|
ALTER TABLE handmade_links RENAME TO link;
|
||||||
|
ALTER TABLE handmade_onetimetoken RENAME TO one_time_token;
|
||||||
|
ALTER TABLE handmade_otherfile RENAME TO other_file;
|
||||||
|
ALTER TABLE handmade_podcast RENAME TO podcast;
|
||||||
|
ALTER TABLE handmade_podcastepisode RENAME TO podcast_episode;
|
||||||
|
ALTER TABLE handmade_post RENAME TO post;
|
||||||
|
ALTER TABLE handmade_post_asset_usage RENAME TO post_asset_usage;
|
||||||
|
ALTER TABLE handmade_postversion RENAME TO post_version;
|
||||||
|
ALTER TABLE handmade_project RENAME TO project;
|
||||||
|
ALTER TABLE handmade_project_downloads RENAME TO project_download;
|
||||||
|
ALTER TABLE handmade_project_screenshots RENAME TO project_screenshot;
|
||||||
|
ALTER TABLE handmade_snippet RENAME TO snippet;
|
||||||
|
ALTER TABLE handmade_subforum RENAME TO subforum;
|
||||||
|
ALTER TABLE handmade_subforumlastreadinfo RENAME TO subforum_last_read_info;
|
||||||
|
ALTER TABLE handmade_thread RENAME TO thread;
|
||||||
|
ALTER TABLE handmade_threadlastreadinfo RENAME TO thread_last_read_info;
|
||||||
|
ALTER TABLE handmade_user_projects RENAME TO user_project;
|
||||||
|
ALTER TABLE sessions RENAME TO session;
|
||||||
|
ALTER TABLE snippet_tags RENAME TO snippet_tag;
|
||||||
|
ALTER TABLE tags RENAME TO tag;
|
||||||
|
ALTER TABLE twitch_streams RENAME TO twitch_stream;
|
||||||
|
|
||||||
|
ALTER SEQUENCE auth_user_id_seq RENAME TO hmn_user_id_seq;
|
||||||
|
ALTER SEQUENCE discord_outgoingmessages_id_seq RENAME TO discord_outgoing_message_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_category_id_seq RENAME TO subforum_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_categorylastreadinfo_id_seq RENAME TO subforum_last_read_info_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_discord_id_seq RENAME TO discord_user_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_discordmessageembed_id_seq RENAME TO discord_message_embed_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_imagefile_id_seq RENAME TO image_file_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_librarymediatype_id_seq RENAME TO library_media_type_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_libraryresource_id_seq RENAME TO library_resource_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_libraryresource_media_types_id_seq RENAME TO library_resource_media_type_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_libraryresource_topics_id_seq RENAME TO library_resource_topic_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_libraryresourcestar_id_seq RENAME TO library_resource_star_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_librarytopic_id_seq RENAME TO library_topic_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_links_id_seq RENAME TO link_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_onetimetoken_id_seq RENAME TO one_time_token_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_otherfile_id_seq RENAME TO other_file_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_podcast_id_seq RENAME TO podcast_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_post_id_seq RENAME TO post_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_postversion_id_seq RENAME TO post_version_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_project_downloads_id_seq RENAME TO project_download_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_project_id_seq RENAME TO project_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_project_screenshots_id_seq RENAME TO project_screenshot_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_snippet_id_seq RENAME TO snippet_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_thread_id_seq RENAME TO thread_id_seq;
|
||||||
|
ALTER SEQUENCE handmade_threadlastreadinfo_id_seq RENAME TO thread_last_read_info_id_seq;
|
||||||
|
ALTER SEQUENCE tags_id_seq RENAME TO tag_id_seq;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION thread_type_for_post(int) RETURNS int AS $$
|
||||||
|
SELECT thread.type
|
||||||
|
FROM
|
||||||
|
public.post
|
||||||
|
JOIN public.thread ON post.thread_id = thread.id
|
||||||
|
WHERE post.id = $1
|
||||||
|
$$ LANGUAGE SQL;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION project_id_for_post(int) RETURNS int AS $$
|
||||||
|
SELECT thread.project_id
|
||||||
|
FROM
|
||||||
|
public.post
|
||||||
|
JOIN public.thread ON post.thread_id = thread.id
|
||||||
|
WHERE post.id = $1
|
||||||
|
$$ LANGUAGE SQL;
|
||||||
|
`)
|
||||||
|
if err != nil {
|
||||||
|
return oops.New(err, "failed to rename tables")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m RenameEverything) Down(ctx context.Context, tx pgx.Tx) error {
|
||||||
|
panic("Implement me")
|
||||||
|
}
|
|
@ -47,7 +47,7 @@ func GetFullSubforumTree(ctx context.Context, conn *pgxpool.Pool) SubforumTree {
|
||||||
subforums, err := db.Query[Subforum](ctx, conn,
|
subforums, err := db.Query[Subforum](ctx, conn,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_subforum
|
FROM subforum
|
||||||
ORDER BY sort, id ASC
|
ORDER BY sort, id ASC
|
||||||
`,
|
`,
|
||||||
)
|
)
|
||||||
|
|
|
@ -211,7 +211,7 @@ func AdminApprovalQueue(c *RequestContext) ResponseData {
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_links
|
link
|
||||||
WHERE
|
WHERE
|
||||||
user_id = ANY($1)
|
user_id = ANY($1)
|
||||||
ORDER BY ordering ASC
|
ORDER BY ordering ASC
|
||||||
|
@ -258,10 +258,10 @@ func AdminApprovalQueueSubmit(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
user, err := db.QueryOne[models.User](c.Context(), c.Conn,
|
user, err := db.QueryOne[models.User](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT $columns{auth_user}
|
SELECT $columns{hmn_user}
|
||||||
FROM auth_user
|
FROM hmn_user
|
||||||
LEFT JOIN handmade_asset AS auth_user_avatar ON auth_user_avatar.id = auth_user.avatar_asset_id
|
LEFT JOIN asset AS hmn_user_avatar ON hmn_user_avatar.id = hmn_user.avatar_asset_id
|
||||||
WHERE auth_user.id = $1
|
WHERE hmn_user.id = $1
|
||||||
`,
|
`,
|
||||||
userId,
|
userId,
|
||||||
)
|
)
|
||||||
|
@ -277,7 +277,7 @@ func AdminApprovalQueueSubmit(c *RequestContext) ResponseData {
|
||||||
if action == ApprovalQueueActionApprove {
|
if action == ApprovalQueueActionApprove {
|
||||||
_, err := c.Conn.Exec(c.Context(),
|
_, err := c.Conn.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE auth_user
|
UPDATE hmn_user
|
||||||
SET status = $1
|
SET status = $1
|
||||||
WHERE id = $2
|
WHERE id = $2
|
||||||
`,
|
`,
|
||||||
|
@ -291,7 +291,7 @@ func AdminApprovalQueueSubmit(c *RequestContext) ResponseData {
|
||||||
} else if action == ApprovalQueueActionSpammer {
|
} else if action == ApprovalQueueActionSpammer {
|
||||||
_, err := c.Conn.Exec(c.Context(),
|
_, err := c.Conn.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE auth_user
|
UPDATE hmn_user
|
||||||
SET status = $1
|
SET status = $1
|
||||||
WHERE id = $2
|
WHERE id = $2
|
||||||
`,
|
`,
|
||||||
|
@ -336,12 +336,12 @@ func fetchUnapprovedPosts(c *RequestContext) ([]*UnapprovedPost, error) {
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_post AS post
|
post
|
||||||
JOIN handmade_project AS project ON post.project_id = project.id
|
JOIN project ON post.project_id = project.id
|
||||||
JOIN handmade_thread AS thread ON post.thread_id = thread.id
|
JOIN thread ON post.thread_id = thread.id
|
||||||
JOIN handmade_postversion AS ver ON ver.id = post.current_id
|
JOIN post_version AS ver ON ver.id = post.current_id
|
||||||
JOIN auth_user AS author ON author.id = post.author_id
|
JOIN hmn_user AS author ON author.id = post.author_id
|
||||||
LEFT JOIN handmade_asset AS author_avatar ON author_avatar.id = author.avatar_asset_id
|
LEFT JOIN asset AS author_avatar ON author_avatar.id = author.avatar_asset_id
|
||||||
WHERE
|
WHERE
|
||||||
NOT thread.deleted
|
NOT thread.deleted
|
||||||
AND NOT post.deleted
|
AND NOT post.deleted
|
||||||
|
@ -367,7 +367,7 @@ func fetchUnapprovedProjects(c *RequestContext) ([]UnapprovedProject, error) {
|
||||||
`
|
`
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM
|
FROM
|
||||||
auth_user AS u
|
hmn_user AS u
|
||||||
WHERE
|
WHERE
|
||||||
u.status = ANY($1)
|
u.status = ANY($1)
|
||||||
`,
|
`,
|
||||||
|
@ -394,7 +394,7 @@ func fetchUnapprovedProjects(c *RequestContext) ([]UnapprovedProject, error) {
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_links AS link
|
link
|
||||||
WHERE
|
WHERE
|
||||||
link.project_id = ANY($1)
|
link.project_id = ANY($1)
|
||||||
ORDER BY link.ordering ASC
|
ORDER BY link.ordering ASC
|
||||||
|
@ -442,9 +442,9 @@ func deleteAllPostsForUser(ctx context.Context, conn *pgxpool.Pool, userId int)
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_post as post
|
post as post
|
||||||
JOIN handmade_thread AS thread ON post.thread_id = thread.id
|
JOIN thread ON post.thread_id = thread.id
|
||||||
JOIN auth_user AS author ON author.id = post.author_id
|
JOIN hmn_user AS author ON author.id = post.author_id
|
||||||
WHERE author.id = $1
|
WHERE author.id = $1
|
||||||
`,
|
`,
|
||||||
userId,
|
userId,
|
||||||
|
@ -475,8 +475,8 @@ func deleteAllProjectsForUser(ctx context.Context, conn *pgxpool.Pool, userId in
|
||||||
`
|
`
|
||||||
SELECT project.id
|
SELECT project.id
|
||||||
FROM
|
FROM
|
||||||
handmade_project AS project
|
project
|
||||||
JOIN handmade_user_projects AS up ON up.project_id = project.id
|
JOIN user_project AS up ON up.project_id = project.id
|
||||||
WHERE
|
WHERE
|
||||||
up.user_id = $1
|
up.user_id = $1
|
||||||
`,
|
`,
|
||||||
|
@ -489,7 +489,7 @@ func deleteAllProjectsForUser(ctx context.Context, conn *pgxpool.Pool, userId in
|
||||||
if len(projectIDsToDelete) > 0 {
|
if len(projectIDsToDelete) > 0 {
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_project WHERE id = ANY($1)
|
DELETE FROM project WHERE id = ANY($1)
|
||||||
`,
|
`,
|
||||||
projectIDsToDelete,
|
projectIDsToDelete,
|
||||||
)
|
)
|
||||||
|
|
|
@ -21,12 +21,12 @@ func APICheckUsername(c *RequestContext) ResponseData {
|
||||||
c.Perf.StartBlock("SQL", "Fetch user")
|
c.Perf.StartBlock("SQL", "Fetch user")
|
||||||
user, err := db.QueryOne[models.User](c.Context(), c.Conn,
|
user, err := db.QueryOne[models.User](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT $columns{auth_user}
|
SELECT $columns{hmn_user}
|
||||||
FROM
|
FROM
|
||||||
auth_user
|
hmn_user
|
||||||
LEFT JOIN handmade_asset AS auth_user_avatar ON auth_user_avatar.id = auth_user.avatar_asset_id
|
LEFT JOIN asset AS hmn_user_avatar ON hmn_user_avatar.id = hmn_user.avatar_asset_id
|
||||||
WHERE
|
WHERE
|
||||||
LOWER(auth_user.username) = LOWER($1)
|
LOWER(hmn_user.username) = LOWER($1)
|
||||||
AND status = ANY ($2)
|
AND status = ANY ($2)
|
||||||
`,
|
`,
|
||||||
requestedUsername,
|
requestedUsername,
|
||||||
|
|
|
@ -77,10 +77,10 @@ func Login(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
user, err := db.QueryOne[models.User](c.Context(), c.Conn,
|
user, err := db.QueryOne[models.User](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT $columns{auth_user}
|
SELECT $columns{hmn_user}
|
||||||
FROM
|
FROM
|
||||||
auth_user
|
hmn_user
|
||||||
LEFT JOIN handmade_asset AS auth_user_avatar ON auth_user_avatar.id = auth_user.avatar_asset_id
|
LEFT JOIN asset AS hmn_user_avatar ON hmn_user_avatar.id = hmn_user.avatar_asset_id
|
||||||
WHERE LOWER(username) = LOWER($1)
|
WHERE LOWER(username) = LOWER($1)
|
||||||
`,
|
`,
|
||||||
username,
|
username,
|
||||||
|
@ -174,7 +174,7 @@ func RegisterNewUserSubmit(c *RequestContext) ResponseData {
|
||||||
_, err := db.QueryOneScalar[int](c.Context(), c.Conn,
|
_, err := db.QueryOneScalar[int](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM auth_user
|
FROM hmn_user
|
||||||
WHERE LOWER(username) = LOWER($1)
|
WHERE LOWER(username) = LOWER($1)
|
||||||
`,
|
`,
|
||||||
username,
|
username,
|
||||||
|
@ -195,7 +195,7 @@ func RegisterNewUserSubmit(c *RequestContext) ResponseData {
|
||||||
_, err = db.QueryOneScalar[int](c.Context(), c.Conn,
|
_, err = db.QueryOneScalar[int](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM auth_user
|
FROM hmn_user
|
||||||
WHERE LOWER(email) = LOWER($1)
|
WHERE LOWER(email) = LOWER($1)
|
||||||
`,
|
`,
|
||||||
emailAddress,
|
emailAddress,
|
||||||
|
@ -228,7 +228,7 @@ func RegisterNewUserSubmit(c *RequestContext) ResponseData {
|
||||||
var newUserId int
|
var newUserId int
|
||||||
err = tx.QueryRow(c.Context(),
|
err = tx.QueryRow(c.Context(),
|
||||||
`
|
`
|
||||||
INSERT INTO auth_user (username, email, password, date_joined, name, registration_ip)
|
INSERT INTO hmn_user (username, email, password, date_joined, name, registration_ip)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`,
|
`,
|
||||||
|
@ -241,7 +241,7 @@ func RegisterNewUserSubmit(c *RequestContext) ResponseData {
|
||||||
ott := models.GenerateToken()
|
ott := models.GenerateToken()
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_onetimetoken (token_type, created, expires, token_content, owner_id)
|
INSERT INTO one_time_token (token_type, created, expires, token_content, owner_id)
|
||||||
VALUES($1, $2, $3, $4, $5)
|
VALUES($1, $2, $3, $4, $5)
|
||||||
`,
|
`,
|
||||||
models.TokenTypeRegistration,
|
models.TokenTypeRegistration,
|
||||||
|
@ -376,7 +376,7 @@ func EmailConfirmationSubmit(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE auth_user
|
UPDATE hmn_user
|
||||||
SET status = $1
|
SET status = $1
|
||||||
WHERE id = $2
|
WHERE id = $2
|
||||||
`,
|
`,
|
||||||
|
@ -389,7 +389,7 @@ func EmailConfirmationSubmit(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_onetimetoken WHERE id = $1
|
DELETE FROM one_time_token WHERE id = $1
|
||||||
`,
|
`,
|
||||||
validationResult.OneTimeToken.ID,
|
validationResult.OneTimeToken.ID,
|
||||||
)
|
)
|
||||||
|
@ -453,14 +453,14 @@ func RequestPasswordResetSubmit(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
c.Perf.StartBlock("SQL", "Fetching user")
|
c.Perf.StartBlock("SQL", "Fetching user")
|
||||||
type userQuery struct {
|
type userQuery struct {
|
||||||
User models.User `db:"auth_user"`
|
User models.User `db:"hmn_user"`
|
||||||
}
|
}
|
||||||
user, err := db.QueryOne[models.User](c.Context(), c.Conn,
|
user, err := db.QueryOne[models.User](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT $columns{auth_user}
|
SELECT $columns{hmn_user}
|
||||||
FROM
|
FROM
|
||||||
auth_user
|
hmn_user
|
||||||
LEFT JOIN handmade_asset AS auth_user_avatar ON auth_user_avatar.id = auth_user.avatar_asset_id
|
LEFT JOIN asset AS hmn_user_avatar ON hmn_user_avatar.id = hmn_user.avatar_asset_id
|
||||||
WHERE
|
WHERE
|
||||||
LOWER(username) = LOWER($1)
|
LOWER(username) = LOWER($1)
|
||||||
AND LOWER(email) = LOWER($2)
|
AND LOWER(email) = LOWER($2)
|
||||||
|
@ -480,7 +480,7 @@ func RequestPasswordResetSubmit(c *RequestContext) ResponseData {
|
||||||
resetToken, err := db.QueryOne[models.OneTimeToken](c.Context(), c.Conn,
|
resetToken, err := db.QueryOne[models.OneTimeToken](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_onetimetoken
|
FROM one_time_token
|
||||||
WHERE
|
WHERE
|
||||||
token_type = $1
|
token_type = $1
|
||||||
AND owner_id = $2
|
AND owner_id = $2
|
||||||
|
@ -501,7 +501,7 @@ func RequestPasswordResetSubmit(c *RequestContext) ResponseData {
|
||||||
c.Perf.StartBlock("SQL", "Deleting expired token")
|
c.Perf.StartBlock("SQL", "Deleting expired token")
|
||||||
_, err = c.Conn.Exec(c.Context(),
|
_, err = c.Conn.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_onetimetoken
|
DELETE FROM one_time_token
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
resetToken.ID,
|
resetToken.ID,
|
||||||
|
@ -518,7 +518,7 @@ func RequestPasswordResetSubmit(c *RequestContext) ResponseData {
|
||||||
c.Perf.StartBlock("SQL", "Creating new token")
|
c.Perf.StartBlock("SQL", "Creating new token")
|
||||||
newToken, err := db.QueryOne[models.OneTimeToken](c.Context(), c.Conn,
|
newToken, err := db.QueryOne[models.OneTimeToken](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_onetimetoken (token_type, created, expires, token_content, owner_id)
|
INSERT INTO one_time_token (token_type, created, expires, token_content, owner_id)
|
||||||
VALUES ($1, $2, $3, $4, $5)
|
VALUES ($1, $2, $3, $4, $5)
|
||||||
RETURNING $columns
|
RETURNING $columns
|
||||||
`,
|
`,
|
||||||
|
@ -630,7 +630,7 @@ func DoPasswordResetSubmit(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
tag, err := tx.Exec(c.Context(),
|
tag, err := tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE auth_user
|
UPDATE hmn_user
|
||||||
SET password = $1
|
SET password = $1
|
||||||
WHERE id = $2
|
WHERE id = $2
|
||||||
`,
|
`,
|
||||||
|
@ -644,7 +644,7 @@ func DoPasswordResetSubmit(c *RequestContext) ResponseData {
|
||||||
if validationResult.User.Status == models.UserStatusInactive {
|
if validationResult.User.Status == models.UserStatusInactive {
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE auth_user
|
UPDATE hmn_user
|
||||||
SET status = $1
|
SET status = $1
|
||||||
WHERE id = $2
|
WHERE id = $2
|
||||||
`,
|
`,
|
||||||
|
@ -658,7 +658,7 @@ func DoPasswordResetSubmit(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_onetimetoken
|
DELETE FROM one_time_token
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
validationResult.OneTimeToken.ID,
|
validationResult.OneTimeToken.ID,
|
||||||
|
@ -725,7 +725,7 @@ func loginUser(c *RequestContext, user *models.User, responseData *ResponseData)
|
||||||
|
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE auth_user
|
UPDATE hmn_user
|
||||||
SET last_login = $1
|
SET last_login = $1
|
||||||
WHERE id = $2
|
WHERE id = $2
|
||||||
`,
|
`,
|
||||||
|
@ -773,17 +773,17 @@ func validateUsernameAndToken(c *RequestContext, username string, token string,
|
||||||
c.Perf.StartBlock("SQL", "Check username and token")
|
c.Perf.StartBlock("SQL", "Check username and token")
|
||||||
defer c.Perf.EndBlock()
|
defer c.Perf.EndBlock()
|
||||||
type userAndTokenQuery struct {
|
type userAndTokenQuery struct {
|
||||||
User models.User `db:"auth_user"`
|
User models.User `db:"hmn_user"`
|
||||||
OneTimeToken *models.OneTimeToken `db:"onetimetoken"`
|
OneTimeToken *models.OneTimeToken `db:"onetimetoken"`
|
||||||
}
|
}
|
||||||
data, err := db.QueryOne[userAndTokenQuery](c.Context(), c.Conn,
|
data, err := db.QueryOne[userAndTokenQuery](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM auth_user
|
FROM hmn_user
|
||||||
LEFT JOIN handmade_asset AS auth_user_avatar ON auth_user_avatar.id = auth_user.avatar_asset_id
|
LEFT JOIN asset AS hmn_user_avatar ON hmn_user_avatar.id = hmn_user.avatar_asset_id
|
||||||
LEFT JOIN handmade_onetimetoken AS onetimetoken ON onetimetoken.owner_id = auth_user.id
|
LEFT JOIN one_time_token AS onetimetoken ON onetimetoken.owner_id = hmn_user.id
|
||||||
WHERE
|
WHERE
|
||||||
LOWER(auth_user.username) = LOWER($1)
|
LOWER(hmn_user.username) = LOWER($1)
|
||||||
AND onetimetoken.token_type = $2
|
AND onetimetoken.token_type = $2
|
||||||
`,
|
`,
|
||||||
username,
|
username,
|
||||||
|
|
|
@ -155,7 +155,7 @@ func BlogThread(c *RequestContext) ResponseData {
|
||||||
c.Perf.StartBlock("SQL", "Update TLRI")
|
c.Perf.StartBlock("SQL", "Update TLRI")
|
||||||
_, err := c.Conn.Exec(c.Context(),
|
_, err := c.Conn.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_threadlastreadinfo (thread_id, user_id, lastread)
|
INSERT INTO thread_last_read_info (thread_id, user_id, lastread)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
ON CONFLICT (thread_id, user_id) DO UPDATE
|
ON CONFLICT (thread_id, user_id) DO UPDATE
|
||||||
SET lastread = EXCLUDED.lastread
|
SET lastread = EXCLUDED.lastread
|
||||||
|
@ -248,7 +248,7 @@ func BlogNewThreadSubmit(c *RequestContext) ResponseData {
|
||||||
var threadId int
|
var threadId int
|
||||||
err = tx.QueryRow(c.Context(),
|
err = tx.QueryRow(c.Context(),
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_thread (title, type, project_id, first_id, last_id)
|
INSERT INTO thread (title, type, project_id, first_id, last_id)
|
||||||
VALUES ($1, $2, $3, $4, $5)
|
VALUES ($1, $2, $3, $4, $5)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`,
|
`,
|
||||||
|
@ -360,7 +360,7 @@ func BlogPostEditSubmit(c *RequestContext) ResponseData {
|
||||||
if title != "" {
|
if title != "" {
|
||||||
_, err := tx.Exec(c.Context(),
|
_, err := tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE handmade_thread SET title = $1 WHERE id = $2
|
UPDATE thread SET title = $1 WHERE id = $2
|
||||||
`,
|
`,
|
||||||
title,
|
title,
|
||||||
post.Thread.ID,
|
post.Thread.ID,
|
||||||
|
@ -561,7 +561,7 @@ func getCommonBlogData(c *RequestContext) (commonBlogData, bool) {
|
||||||
threadExists, err := db.QueryOneScalar[bool](c.Context(), c.Conn,
|
threadExists, err := db.QueryOneScalar[bool](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT COUNT(*) > 0
|
SELECT COUNT(*) > 0
|
||||||
FROM handmade_thread
|
FROM thread
|
||||||
WHERE
|
WHERE
|
||||||
id = $1
|
id = $1
|
||||||
AND project_id = $2
|
AND project_id = $2
|
||||||
|
@ -589,7 +589,7 @@ func getCommonBlogData(c *RequestContext) (commonBlogData, bool) {
|
||||||
postExists, err := db.QueryOneScalar[bool](c.Context(), c.Conn,
|
postExists, err := db.QueryOneScalar[bool](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT COUNT(*) > 0
|
SELECT COUNT(*) > 0
|
||||||
FROM handmade_post
|
FROM post
|
||||||
WHERE
|
WHERE
|
||||||
id = $1
|
id = $1
|
||||||
AND thread_id = $2
|
AND thread_id = $2
|
||||||
|
|
|
@ -61,7 +61,7 @@ func DiscordOAuthCallback(c *RequestContext) ResponseData {
|
||||||
// Add the user to our database
|
// Add the user to our database
|
||||||
_, err = c.Conn.Exec(c.Context(),
|
_, err = c.Conn.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_discorduser (username, discriminator, access_token, refresh_token, avatar, locale, userid, expiry, hmn_user_id)
|
INSERT INTO discord_user (username, discriminator, access_token, refresh_token, avatar, locale, userid, expiry, hmn_user_id)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||||
`,
|
`,
|
||||||
user.Username,
|
user.Username,
|
||||||
|
@ -81,7 +81,7 @@ func DiscordOAuthCallback(c *RequestContext) ResponseData {
|
||||||
if c.CurrentUser.Status == models.UserStatusConfirmed {
|
if c.CurrentUser.Status == models.UserStatusConfirmed {
|
||||||
_, err = c.Conn.Exec(c.Context(),
|
_, err = c.Conn.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE auth_user
|
UPDATE hmn_user
|
||||||
SET status = $1
|
SET status = $1
|
||||||
WHERE id = $2
|
WHERE id = $2
|
||||||
`,
|
`,
|
||||||
|
@ -107,7 +107,7 @@ func DiscordUnlink(c *RequestContext) ResponseData {
|
||||||
discordUser, err := db.QueryOne[models.DiscordUser](c.Context(), tx,
|
discordUser, err := db.QueryOne[models.DiscordUser](c.Context(), tx,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_discorduser
|
FROM discord_user
|
||||||
WHERE hmn_user_id = $1
|
WHERE hmn_user_id = $1
|
||||||
`,
|
`,
|
||||||
c.CurrentUser.ID,
|
c.CurrentUser.ID,
|
||||||
|
@ -122,7 +122,7 @@ func DiscordUnlink(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_discorduser
|
DELETE FROM discord_user
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
discordUser.ID,
|
discordUser.ID,
|
||||||
|
@ -146,7 +146,7 @@ func DiscordUnlink(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
func DiscordShowcaseBacklog(c *RequestContext) ResponseData {
|
func DiscordShowcaseBacklog(c *RequestContext) ResponseData {
|
||||||
duser, err := db.QueryOne[models.DiscordUser](c.Context(), c.Conn,
|
duser, err := db.QueryOne[models.DiscordUser](c.Context(), c.Conn,
|
||||||
`SELECT $columns FROM handmade_discorduser WHERE hmn_user_id = $1`,
|
`SELECT $columns FROM discord_user WHERE hmn_user_id = $1`,
|
||||||
c.CurrentUser.ID,
|
c.CurrentUser.ID,
|
||||||
)
|
)
|
||||||
if errors.Is(err, db.NotFound) {
|
if errors.Is(err, db.NotFound) {
|
||||||
|
@ -161,7 +161,7 @@ func DiscordShowcaseBacklog(c *RequestContext) ResponseData {
|
||||||
`
|
`
|
||||||
SELECT msg.id
|
SELECT msg.id
|
||||||
FROM
|
FROM
|
||||||
handmade_discordmessage AS msg
|
discord_message AS msg
|
||||||
WHERE
|
WHERE
|
||||||
msg.user_id = $1
|
msg.user_id = $1
|
||||||
AND msg.channel_id = $2
|
AND msg.channel_id = $2
|
||||||
|
|
|
@ -223,7 +223,7 @@ func ForumMarkRead(c *RequestContext) ResponseData {
|
||||||
// Mark literally everything as read
|
// Mark literally everything as read
|
||||||
_, err := tx.Exec(c.Context(),
|
_, err := tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE auth_user
|
UPDATE hmn_user
|
||||||
SET marked_all_read_at = NOW()
|
SET marked_all_read_at = NOW()
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`,
|
`,
|
||||||
|
@ -236,7 +236,7 @@ func ForumMarkRead(c *RequestContext) ResponseData {
|
||||||
// Delete thread unread info
|
// Delete thread unread info
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_threadlastreadinfo
|
DELETE FROM thread_last_read_info
|
||||||
WHERE user_id = $1;
|
WHERE user_id = $1;
|
||||||
`,
|
`,
|
||||||
c.CurrentUser.ID,
|
c.CurrentUser.ID,
|
||||||
|
@ -248,7 +248,7 @@ func ForumMarkRead(c *RequestContext) ResponseData {
|
||||||
// Delete subforum unread info
|
// Delete subforum unread info
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_subforumlastreadinfo
|
DELETE FROM subforum_last_read_info
|
||||||
WHERE user_id = $1;
|
WHERE user_id = $1;
|
||||||
`,
|
`,
|
||||||
c.CurrentUser.ID,
|
c.CurrentUser.ID,
|
||||||
|
@ -260,9 +260,9 @@ func ForumMarkRead(c *RequestContext) ResponseData {
|
||||||
c.Perf.StartBlock("SQL", "Update SLRIs")
|
c.Perf.StartBlock("SQL", "Update SLRIs")
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_subforumlastreadinfo (subforum_id, user_id, lastread)
|
INSERT INTO subforum_last_read_info (subforum_id, user_id, lastread)
|
||||||
SELECT id, $2, $3
|
SELECT id, $2, $3
|
||||||
FROM handmade_subforum
|
FROM subforum
|
||||||
WHERE id = ANY ($1)
|
WHERE id = ANY ($1)
|
||||||
ON CONFLICT (subforum_id, user_id) DO UPDATE
|
ON CONFLICT (subforum_id, user_id) DO UPDATE
|
||||||
SET lastread = EXCLUDED.lastread
|
SET lastread = EXCLUDED.lastread
|
||||||
|
@ -279,12 +279,12 @@ func ForumMarkRead(c *RequestContext) ResponseData {
|
||||||
c.Perf.StartBlock("SQL", "Delete TLRIs")
|
c.Perf.StartBlock("SQL", "Delete TLRIs")
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_threadlastreadinfo
|
DELETE FROM thread_last_read_info
|
||||||
WHERE
|
WHERE
|
||||||
user_id = $2
|
user_id = $2
|
||||||
AND thread_id IN (
|
AND thread_id IN (
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM handmade_thread
|
FROM thread
|
||||||
WHERE
|
WHERE
|
||||||
subforum_id = ANY ($1)
|
subforum_id = ANY ($1)
|
||||||
)
|
)
|
||||||
|
@ -402,7 +402,7 @@ func ForumThread(c *RequestContext) ResponseData {
|
||||||
c.Perf.StartBlock("SQL", "Update TLRI")
|
c.Perf.StartBlock("SQL", "Update TLRI")
|
||||||
_, err = c.Conn.Exec(c.Context(),
|
_, err = c.Conn.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_threadlastreadinfo (thread_id, user_id, lastread)
|
INSERT INTO thread_last_read_info (thread_id, user_id, lastread)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
ON CONFLICT (thread_id, user_id) DO UPDATE
|
ON CONFLICT (thread_id, user_id) DO UPDATE
|
||||||
SET lastread = EXCLUDED.lastread
|
SET lastread = EXCLUDED.lastread
|
||||||
|
@ -523,7 +523,7 @@ func ForumNewThreadSubmit(c *RequestContext) ResponseData {
|
||||||
var threadId int
|
var threadId int
|
||||||
err = tx.QueryRow(c.Context(),
|
err = tx.QueryRow(c.Context(),
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_thread (title, sticky, type, project_id, subforum_id, first_id, last_id)
|
INSERT INTO thread (title, sticky, type, project_id, subforum_id, first_id, last_id)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`,
|
`,
|
||||||
|
@ -710,7 +710,7 @@ func ForumPostEditSubmit(c *RequestContext) ResponseData {
|
||||||
if title != "" {
|
if title != "" {
|
||||||
_, err := tx.Exec(c.Context(),
|
_, err := tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE handmade_thread SET title = $1 WHERE id = $2
|
UPDATE thread SET title = $1 WHERE id = $2
|
||||||
`,
|
`,
|
||||||
title,
|
title,
|
||||||
post.Thread.ID,
|
post.Thread.ID,
|
||||||
|
@ -940,8 +940,8 @@ func addAuthorCountsToPost(ctx context.Context, conn db.ConnOrTx, p *templates.P
|
||||||
`
|
`
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
handmade_post AS post
|
post
|
||||||
JOIN handmade_project AS project ON post.project_id = project.id
|
JOIN project ON post.project_id = project.id
|
||||||
WHERE
|
WHERE
|
||||||
post.author_id = $1
|
post.author_id = $1
|
||||||
AND NOT post.deleted
|
AND NOT post.deleted
|
||||||
|
@ -960,8 +960,8 @@ func addAuthorCountsToPost(ctx context.Context, conn db.ConnOrTx, p *templates.P
|
||||||
`
|
`
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
handmade_project AS project
|
project
|
||||||
JOIN handmade_user_projects AS uproj ON uproj.project_id = project.id
|
JOIN user_project AS uproj ON uproj.project_id = project.id
|
||||||
WHERE
|
WHERE
|
||||||
project.lifecycle = ANY ($1)
|
project.lifecycle = ANY ($1)
|
||||||
AND uproj.user_id = $2
|
AND uproj.user_id = $2
|
||||||
|
|
|
@ -91,7 +91,7 @@ func SaveImageFile(c *RequestContext, dbConn db.ConnOrTx, fileFieldName string,
|
||||||
sha1sum := hasher.Sum(nil)
|
sha1sum := hasher.Sum(nil)
|
||||||
imageFile, err := db.QueryOne[models.ImageFile](c.Context(), dbConn,
|
imageFile, err := db.QueryOne[models.ImageFile](c.Context(), dbConn,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_imagefile (file, size, sha1sum, protected, width, height)
|
INSERT INTO image_file (file, size, sha1sum, protected, width, height)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
RETURNING $columns
|
RETURNING $columns
|
||||||
`,
|
`,
|
||||||
|
|
|
@ -150,7 +150,7 @@ func PodcastEditSubmit(c *RequestContext) ResponseData {
|
||||||
if imageSaveResult.ImageFile != nil {
|
if imageSaveResult.ImageFile != nil {
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE handmade_podcast
|
UPDATE podcast
|
||||||
SET
|
SET
|
||||||
title = $1,
|
title = $1,
|
||||||
description = $2,
|
description = $2,
|
||||||
|
@ -168,7 +168,7 @@ func PodcastEditSubmit(c *RequestContext) ResponseData {
|
||||||
} else {
|
} else {
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE handmade_podcast
|
UPDATE podcast
|
||||||
SET
|
SET
|
||||||
title = $1,
|
title = $1,
|
||||||
description = $2
|
description = $2
|
||||||
|
@ -419,7 +419,7 @@ func PodcastEpisodeSubmit(c *RequestContext) ResponseData {
|
||||||
c.Perf.StartBlock("SQL", "Updating podcast episode")
|
c.Perf.StartBlock("SQL", "Updating podcast episode")
|
||||||
_, err := c.Conn.Exec(c.Context(),
|
_, err := c.Conn.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE handmade_podcastepisode
|
UPDATE podcast_episode
|
||||||
SET
|
SET
|
||||||
title = $1,
|
title = $1,
|
||||||
description = $2,
|
description = $2,
|
||||||
|
@ -448,7 +448,7 @@ func PodcastEpisodeSubmit(c *RequestContext) ResponseData {
|
||||||
c.Perf.StartBlock("SQL", "Creating new podcast episode")
|
c.Perf.StartBlock("SQL", "Creating new podcast episode")
|
||||||
_, err := c.Conn.Exec(c.Context(),
|
_, err := c.Conn.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_podcastepisode
|
INSERT INTO podcast_episode
|
||||||
(guid, title, description, description_rendered, audio_filename, duration, pub_date, episode_number, podcast_id)
|
(guid, title, description, description_rendered, audio_filename, duration, pub_date, episode_number, podcast_id)
|
||||||
VALUES
|
VALUES
|
||||||
($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||||
|
@ -536,8 +536,8 @@ func FetchPodcast(c *RequestContext, projectId int, fetchEpisodes bool, episodeG
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_podcast AS podcast
|
podcast
|
||||||
LEFT JOIN handmade_imagefile AS imagefile ON imagefile.id = podcast.image_id
|
LEFT JOIN image_file AS imagefile ON imagefile.id = podcast.image_id
|
||||||
WHERE podcast.project_id = $1
|
WHERE podcast.project_id = $1
|
||||||
`,
|
`,
|
||||||
projectId,
|
projectId,
|
||||||
|
@ -561,7 +561,7 @@ func FetchPodcast(c *RequestContext, projectId int, fetchEpisodes bool, episodeG
|
||||||
episodes, err := db.Query[models.PodcastEpisode](c.Context(), c.Conn,
|
episodes, err := db.Query[models.PodcastEpisode](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_podcastepisode AS episode
|
FROM podcast_episode AS episode
|
||||||
WHERE episode.podcast_id = $1
|
WHERE episode.podcast_id = $1
|
||||||
ORDER BY episode.season_number DESC, episode.episode_number DESC
|
ORDER BY episode.season_number DESC, episode.episode_number DESC
|
||||||
`,
|
`,
|
||||||
|
@ -581,7 +581,7 @@ func FetchPodcast(c *RequestContext, projectId int, fetchEpisodes bool, episodeG
|
||||||
episode, err := db.QueryOne[models.PodcastEpisode](c.Context(), c.Conn,
|
episode, err := db.QueryOne[models.PodcastEpisode](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_podcastepisode AS episode
|
FROM podcast_episode AS episode
|
||||||
WHERE episode.podcast_id = $1 AND episode.guid = $2
|
WHERE episode.podcast_id = $1 AND episode.guid = $2
|
||||||
`,
|
`,
|
||||||
podcast.ID,
|
podcast.ID,
|
||||||
|
|
|
@ -191,10 +191,10 @@ func ProjectHomepage(c *RequestContext) ResponseData {
|
||||||
`
|
`
|
||||||
SELECT screenshot.file
|
SELECT screenshot.file
|
||||||
FROM
|
FROM
|
||||||
handmade_imagefile AS screenshot
|
image_file AS screenshot
|
||||||
INNER JOIN handmade_project_screenshots ON screenshot.id = handmade_project_screenshots.imagefile_id
|
INNER JOIN project_screenshot ON screenshot.id = project_screenshot.imagefile_id
|
||||||
WHERE
|
WHERE
|
||||||
handmade_project_screenshots.project_id = $1
|
project_screenshot.project_id = $1
|
||||||
`,
|
`,
|
||||||
c.CurrentProject.ID,
|
c.CurrentProject.ID,
|
||||||
)
|
)
|
||||||
|
@ -208,7 +208,7 @@ func ProjectHomepage(c *RequestContext) ResponseData {
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_links as link
|
link as link
|
||||||
WHERE
|
WHERE
|
||||||
link.project_id = $1
|
link.project_id = $1
|
||||||
ORDER BY link.ordering ASC
|
ORDER BY link.ordering ASC
|
||||||
|
@ -235,10 +235,10 @@ func ProjectHomepage(c *RequestContext) ResponseData {
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_post AS post
|
post
|
||||||
INNER JOIN handmade_thread AS thread ON thread.id = post.thread_id
|
INNER JOIN thread ON thread.id = post.thread_id
|
||||||
INNER JOIN auth_user AS author ON author.id = post.author_id
|
INNER JOIN hmn_user AS author ON author.id = post.author_id
|
||||||
LEFT JOIN handmade_asset AS author_avatar ON author_avatar.id = author.avatar_asset_id
|
LEFT JOIN asset AS author_avatar ON author_avatar.id = author.avatar_asset_id
|
||||||
WHERE
|
WHERE
|
||||||
post.project_id = $1
|
post.project_id = $1
|
||||||
ORDER BY post.postdate DESC
|
ORDER BY post.postdate DESC
|
||||||
|
@ -439,7 +439,7 @@ func ProjectNewSubmit(c *RequestContext) ResponseData {
|
||||||
var projectId int
|
var projectId int
|
||||||
err = tx.QueryRow(c.Context(),
|
err = tx.QueryRow(c.Context(),
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_project
|
INSERT INTO project
|
||||||
(name, blurb, description, descparsed, lifecycle, date_created, all_last_updated)
|
(name, blurb, description, descparsed, lifecycle, date_created, all_last_updated)
|
||||||
VALUES
|
VALUES
|
||||||
($1, $2, $3, $4, $5, $6, $6)
|
($1, $2, $3, $4, $5, $6, $6)
|
||||||
|
@ -496,7 +496,7 @@ func ProjectEdit(c *RequestContext) ResponseData {
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_links as link
|
link as link
|
||||||
WHERE
|
WHERE
|
||||||
link.project_id = $1
|
link.project_id = $1
|
||||||
ORDER BY link.ordering ASC
|
ORDER BY link.ordering ASC
|
||||||
|
@ -736,7 +736,7 @@ func updateProject(ctx context.Context, tx pgx.Tx, user *models.User, payload *P
|
||||||
|
|
||||||
_, err := tx.Exec(ctx,
|
_, err := tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_project SET
|
UPDATE project SET
|
||||||
name = $2,
|
name = $2,
|
||||||
blurb = $3,
|
blurb = $3,
|
||||||
description = $4,
|
description = $4,
|
||||||
|
@ -763,7 +763,7 @@ func updateProject(ctx context.Context, tx pgx.Tx, user *models.User, payload *P
|
||||||
if user.IsStaff {
|
if user.IsStaff {
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_project SET
|
UPDATE project SET
|
||||||
slug = $2,
|
slug = $2,
|
||||||
featured = $3,
|
featured = $3,
|
||||||
personal = $4,
|
personal = $4,
|
||||||
|
@ -785,7 +785,7 @@ func updateProject(ctx context.Context, tx pgx.Tx, user *models.User, payload *P
|
||||||
if payload.LightLogo.Exists || payload.LightLogo.Remove {
|
if payload.LightLogo.Exists || payload.LightLogo.Remove {
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_project
|
UPDATE project
|
||||||
SET
|
SET
|
||||||
logolight_asset_id = $2
|
logolight_asset_id = $2
|
||||||
WHERE
|
WHERE
|
||||||
|
@ -802,7 +802,7 @@ func updateProject(ctx context.Context, tx pgx.Tx, user *models.User, payload *P
|
||||||
if payload.DarkLogo.Exists || payload.DarkLogo.Remove {
|
if payload.DarkLogo.Exists || payload.DarkLogo.Remove {
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
UPDATE handmade_project
|
UPDATE project
|
||||||
SET
|
SET
|
||||||
logodark_asset_id = $2
|
logodark_asset_id = $2
|
||||||
WHERE
|
WHERE
|
||||||
|
@ -818,10 +818,10 @@ func updateProject(ctx context.Context, tx pgx.Tx, user *models.User, payload *P
|
||||||
|
|
||||||
owners, err := db.Query[models.User](ctx, tx,
|
owners, err := db.Query[models.User](ctx, tx,
|
||||||
`
|
`
|
||||||
SELECT $columns{auth_user}
|
SELECT $columns{hmn_user}
|
||||||
FROM
|
FROM
|
||||||
auth_user
|
hmn_user
|
||||||
LEFT JOIN handmade_asset AS auth_user_avatar ON auth_user_avatar.id = auth_user.avatar_asset_id
|
LEFT JOIN asset AS hmn_user_avatar ON hmn_user_avatar.id = hmn_user.avatar_asset_id
|
||||||
WHERE LOWER(username) = ANY ($1)
|
WHERE LOWER(username) = ANY ($1)
|
||||||
`,
|
`,
|
||||||
payload.OwnerUsernames,
|
payload.OwnerUsernames,
|
||||||
|
@ -832,7 +832,7 @@ func updateProject(ctx context.Context, tx pgx.Tx, user *models.User, payload *P
|
||||||
|
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
DELETE FROM handmade_user_projects
|
DELETE FROM user_project
|
||||||
WHERE project_id = $1
|
WHERE project_id = $1
|
||||||
`,
|
`,
|
||||||
payload.ProjectID,
|
payload.ProjectID,
|
||||||
|
@ -844,7 +844,7 @@ func updateProject(ctx context.Context, tx pgx.Tx, user *models.User, payload *P
|
||||||
for _, owner := range owners {
|
for _, owner := range owners {
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_user_projects
|
INSERT INTO user_project
|
||||||
(user_id, project_id)
|
(user_id, project_id)
|
||||||
VALUES
|
VALUES
|
||||||
($1, $2)
|
($1, $2)
|
||||||
|
@ -858,14 +858,14 @@ func updateProject(ctx context.Context, tx pgx.Tx, user *models.User, payload *P
|
||||||
}
|
}
|
||||||
|
|
||||||
twitchLoginsPreChange, preErr := hmndata.FetchTwitchLoginsForUserOrProject(ctx, tx, nil, &payload.ProjectID)
|
twitchLoginsPreChange, preErr := hmndata.FetchTwitchLoginsForUserOrProject(ctx, tx, nil, &payload.ProjectID)
|
||||||
_, err = tx.Exec(ctx, `DELETE FROM handmade_links WHERE project_id = $1`, payload.ProjectID)
|
_, err = tx.Exec(ctx, `DELETE FROM link WHERE project_id = $1`, payload.ProjectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return oops.New(err, "Failed to delete project links")
|
return oops.New(err, "Failed to delete project links")
|
||||||
}
|
}
|
||||||
for i, link := range payload.Links {
|
for i, link := range payload.Links {
|
||||||
_, err = tx.Exec(ctx,
|
_, err = tx.Exec(ctx,
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_links (name, url, ordering, project_id)
|
INSERT INTO link (name, url, ordering, project_id)
|
||||||
VALUES ($1, $2, $3, $4)
|
VALUES ($1, $2, $3, $4)
|
||||||
`,
|
`,
|
||||||
link.Name,
|
link.Name,
|
||||||
|
|
|
@ -550,10 +550,10 @@ func getCurrentUserAndSession(c *RequestContext, sessionId string) (*models.User
|
||||||
|
|
||||||
user, err := db.QueryOne[models.User](c.Context(), c.Conn,
|
user, err := db.QueryOne[models.User](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT $columns{auth_user}
|
SELECT $columns{hmn_user}
|
||||||
FROM
|
FROM
|
||||||
auth_user
|
hmn_user
|
||||||
LEFT JOIN handmade_asset AS auth_user_avatar ON auth_user_avatar.id = auth_user.avatar_asset_id
|
LEFT JOIN asset AS hmn_user_avatar ON hmn_user_avatar.id = hmn_user.avatar_asset_id
|
||||||
WHERE username = $1
|
WHERE username = $1
|
||||||
`,
|
`,
|
||||||
session.Username,
|
session.Username,
|
||||||
|
|
|
@ -55,12 +55,12 @@ func UserProfile(c *RequestContext) ResponseData {
|
||||||
c.Perf.StartBlock("SQL", "Fetch user")
|
c.Perf.StartBlock("SQL", "Fetch user")
|
||||||
user, err := db.QueryOne[models.User](c.Context(), c.Conn,
|
user, err := db.QueryOne[models.User](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT $columns{auth_user}
|
SELECT $columns{hmn_user}
|
||||||
FROM
|
FROM
|
||||||
auth_user
|
hmn_user
|
||||||
LEFT JOIN handmade_asset AS auth_user_avatar ON auth_user_avatar.id = auth_user.avatar_asset_id
|
LEFT JOIN asset AS hmn_user_avatar ON hmn_user_avatar.id = hmn_user.avatar_asset_id
|
||||||
WHERE
|
WHERE
|
||||||
LOWER(auth_user.username) = $1
|
LOWER(hmn_user.username) = $1
|
||||||
`,
|
`,
|
||||||
username,
|
username,
|
||||||
)
|
)
|
||||||
|
@ -88,7 +88,7 @@ func UserProfile(c *RequestContext) ResponseData {
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM
|
FROM
|
||||||
handmade_links as link
|
link as link
|
||||||
WHERE
|
WHERE
|
||||||
link.user_id = $1
|
link.user_id = $1
|
||||||
ORDER BY link.ordering ASC
|
ORDER BY link.ordering ASC
|
||||||
|
@ -228,7 +228,7 @@ func UserSettings(c *RequestContext) ResponseData {
|
||||||
links, err := db.Query[models.Link](c.Context(), c.Conn,
|
links, err := db.Query[models.Link](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_links
|
FROM link
|
||||||
WHERE user_id = $1
|
WHERE user_id = $1
|
||||||
ORDER BY ordering
|
ORDER BY ordering
|
||||||
`,
|
`,
|
||||||
|
@ -245,7 +245,7 @@ func UserSettings(c *RequestContext) ResponseData {
|
||||||
duser, err := db.QueryOne[models.DiscordUser](c.Context(), c.Conn,
|
duser, err := db.QueryOne[models.DiscordUser](c.Context(), c.Conn,
|
||||||
`
|
`
|
||||||
SELECT $columns
|
SELECT $columns
|
||||||
FROM handmade_discorduser
|
FROM discord_user
|
||||||
WHERE hmn_user_id = $1
|
WHERE hmn_user_id = $1
|
||||||
`,
|
`,
|
||||||
c.CurrentUser.ID,
|
c.CurrentUser.ID,
|
||||||
|
@ -262,8 +262,8 @@ func UserSettings(c *RequestContext) ResponseData {
|
||||||
`
|
`
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM
|
FROM
|
||||||
handmade_discordmessage AS msg
|
discord_message AS msg
|
||||||
LEFT JOIN handmade_discordmessagecontent AS c ON c.message_id = msg.id
|
LEFT JOIN discord_message_content AS c ON c.message_id = msg.id
|
||||||
WHERE
|
WHERE
|
||||||
msg.user_id = $1
|
msg.user_id = $1
|
||||||
AND msg.channel_id = $2
|
AND msg.channel_id = $2
|
||||||
|
@ -342,7 +342,7 @@ func UserSettingsSave(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
_, err = tx.Exec(c.Context(),
|
_, err = tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE auth_user
|
UPDATE hmn_user
|
||||||
SET
|
SET
|
||||||
name = $2,
|
name = $2,
|
||||||
email = $3,
|
email = $3,
|
||||||
|
@ -375,14 +375,14 @@ func UserSettingsSave(c *RequestContext) ResponseData {
|
||||||
twitchLoginsPreChange, preErr := hmndata.FetchTwitchLoginsForUserOrProject(c.Context(), tx, &c.CurrentUser.ID, nil)
|
twitchLoginsPreChange, preErr := hmndata.FetchTwitchLoginsForUserOrProject(c.Context(), tx, &c.CurrentUser.ID, nil)
|
||||||
linksText := form.Get("links")
|
linksText := form.Get("links")
|
||||||
links := ParseLinks(linksText)
|
links := ParseLinks(linksText)
|
||||||
_, err = tx.Exec(c.Context(), `DELETE FROM handmade_links WHERE user_id = $1`, c.CurrentUser.ID)
|
_, err = tx.Exec(c.Context(), `DELETE FROM link WHERE user_id = $1`, c.CurrentUser.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Logger.Warn().Err(err).Msg("failed to delete old links")
|
c.Logger.Warn().Err(err).Msg("failed to delete old links")
|
||||||
} else {
|
} else {
|
||||||
for i, link := range links {
|
for i, link := range links {
|
||||||
_, err := tx.Exec(c.Context(),
|
_, err := tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
INSERT INTO handmade_links (name, url, ordering, user_id)
|
INSERT INTO link (name, url, ordering, user_id)
|
||||||
VALUES ($1, $2, $3, $4)
|
VALUES ($1, $2, $3, $4)
|
||||||
`,
|
`,
|
||||||
link.Name,
|
link.Name,
|
||||||
|
@ -435,7 +435,7 @@ func UserSettingsSave(c *RequestContext) ResponseData {
|
||||||
if newAvatar.Exists || newAvatar.Remove {
|
if newAvatar.Exists || newAvatar.Remove {
|
||||||
_, err := tx.Exec(c.Context(),
|
_, err := tx.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE auth_user
|
UPDATE hmn_user
|
||||||
SET
|
SET
|
||||||
avatar_asset_id = $2
|
avatar_asset_id = $2
|
||||||
WHERE
|
WHERE
|
||||||
|
@ -486,7 +486,7 @@ func UserProfileAdminSetStatus(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
_, err = c.Conn.Exec(c.Context(),
|
_, err = c.Conn.Exec(c.Context(),
|
||||||
`
|
`
|
||||||
UPDATE auth_user
|
UPDATE hmn_user
|
||||||
SET status = $1
|
SET status = $1
|
||||||
WHERE id = $2
|
WHERE id = $2
|
||||||
`,
|
`,
|
||||||
|
|
Loading…
Reference in New Issue