[bugfix] Remove hardcoded "public" db schema assumption (#4269)

This pull request closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4257 by removing the hardcoded "public" schema assumption in the database migrations. Tested on a local postgres with both the default public schema, and with the connection string (gotosocial schema) mentioned in the issue. Both seem to work OK!

Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4269
Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Co-committed-by: tobi <tobi.smethurst@protonmail.com>
This commit is contained in:
tobi 2025-06-13 16:05:00 +02:00 committed by tobi
commit 726584287a
5 changed files with 44 additions and 43 deletions

View file

@ -48,79 +48,79 @@ func init() {
{ {
old: "new_accounts_pkey", old: "new_accounts_pkey",
new: "accounts_pkey", new: "accounts_pkey",
table: "public.accounts", table: "accounts",
columns: []string{"id"}, columns: []string{"id"},
}, },
{ {
old: "new_accounts_uri_key", old: "new_accounts_uri_key",
new: "accounts_uri_key", new: "accounts_uri_key",
table: "public.accounts", table: "accounts",
columns: []string{"uri"}, columns: []string{"uri"},
}, },
{ {
old: "new_accounts_url_key", old: "new_accounts_url_key",
new: "accounts_url_key", new: "accounts_url_key",
table: "public.accounts", table: "accounts",
columns: []string{"url"}, columns: []string{"url"},
}, },
{ {
old: "new_accounts_inbox_uri_key", old: "new_accounts_inbox_uri_key",
new: "accounts_inbox_uri_key", new: "accounts_inbox_uri_key",
table: "public.accounts", table: "accounts",
columns: []string{"inbox_uri"}, columns: []string{"inbox_uri"},
}, },
{ {
old: "new_accounts_outbox_uri_key", old: "new_accounts_outbox_uri_key",
new: "accounts_outbox_uri_key", new: "accounts_outbox_uri_key",
table: "public.accounts", table: "accounts",
columns: []string{"outbox_uri"}, columns: []string{"outbox_uri"},
}, },
{ {
old: "new_accounts_following_uri_key", old: "new_accounts_following_uri_key",
new: "accounts_following_uri_key", new: "accounts_following_uri_key",
table: "public.accounts", table: "accounts",
columns: []string{"following_uri"}, columns: []string{"following_uri"},
}, },
{ {
old: "new_accounts_followers_uri_key", old: "new_accounts_followers_uri_key",
new: "accounts_followers_uri_key", new: "accounts_followers_uri_key",
table: "public.accounts", table: "accounts",
columns: []string{"followers_uri"}, columns: []string{"followers_uri"},
}, },
{ {
old: "new_accounts_featured_collection_uri_key", old: "new_accounts_featured_collection_uri_key",
new: "accounts_featured_collection_uri_key", new: "accounts_featured_collection_uri_key",
table: "public.accounts", table: "accounts",
columns: []string{"featured_collection_uri"}, columns: []string{"featured_collection_uri"},
}, },
{ {
old: "new_accounts_public_key_uri_key", old: "new_accounts_public_key_uri_key",
new: "accounts_public_key_uri_key", new: "accounts_public_key_uri_key",
table: "public.accounts", table: "accounts",
columns: []string{"public_key_uri"}, columns: []string{"public_key_uri"},
}, },
{ {
old: "new_emojis_pkey1", old: "new_emojis_pkey1",
new: "emojis_pkey", new: "emojis_pkey",
table: "public.emojis", table: "emojis",
columns: []string{"id"}, columns: []string{"id"},
}, },
{ {
old: "new_emojis_uri_key1", old: "new_emojis_uri_key1",
new: "emojis_uri_key", new: "emojis_uri_key",
table: "public.emojis", table: "emojis",
columns: []string{"uri"}, columns: []string{"uri"},
}, },
{ {
old: "new_status_faves_pkey", old: "new_status_faves_pkey",
new: "status_faves_pkey", new: "status_faves_pkey",
table: "public.status_faves", table: "status_faves",
columns: []string{"id"}, columns: []string{"id"},
}, },
{ {
old: "new_status_faves_uri_key", old: "new_status_faves_uri_key",
new: "status_faves_uri_key", new: "status_faves_uri_key",
table: "public.status_faves", table: "status_faves",
columns: []string{"uri"}, columns: []string{"uri"},
}, },
} { } {

View file

@ -86,8 +86,8 @@ func init() {
// query from running. // query from running.
if db.Dialect().Name() == dialect.PG { if db.Dialect().Name() == dialect.PG {
for _, table := range []string{ for _, table := range []string{
"public.header_filter_allows", "header_filter_allows",
"public.header_filter_blocks", "header_filter_blocks",
} { } {
// Just swallow any errors // Just swallow any errors
// here, we're not bothered. // here, we're not bothered.

View file

@ -107,7 +107,7 @@ func init() {
if _, err := tx.ExecContext( if _, err := tx.ExecContext(
ctx, ctx,
"ALTER TABLE ? RENAME CONSTRAINT ? TO ?", "ALTER TABLE ? RENAME CONSTRAINT ? TO ?",
bun.Ident("public.filters"), bun.Ident("filters"),
bun.Safe("new_filters_pkey"), bun.Safe("new_filters_pkey"),
bun.Safe("filters_pkey"), bun.Safe("filters_pkey"),
); err != nil { ); err != nil {

View file

@ -379,7 +379,7 @@ func init() {
if _, err := tx.ExecContext( if _, err := tx.ExecContext(
ctx, ctx,
"ALTER TABLE ? DROP CONSTRAINT IF EXISTS ?", "ALTER TABLE ? DROP CONSTRAINT IF EXISTS ?",
bun.Ident("public.accounts"), bun.Ident("accounts"),
bun.Safe(spec.old), bun.Safe(spec.old),
); err != nil { ); err != nil {
return err return err
@ -388,7 +388,7 @@ func init() {
if _, err := tx.ExecContext( if _, err := tx.ExecContext(
ctx, ctx,
"ALTER TABLE ? ADD CONSTRAINT ? UNIQUE(?)", "ALTER TABLE ? ADD CONSTRAINT ? UNIQUE(?)",
bun.Ident("public.accounts"), bun.Ident("accounts"),
bun.Safe(spec.new), bun.Safe(spec.new),
bun.Safe(strings.Join(spec.columns, ",")), bun.Safe(strings.Join(spec.columns, ",")),
); err != nil { ); err != nil {

View file

@ -56,31 +56,32 @@ func InitTestConfig() {
func testDefaults() config.Configuration { func testDefaults() config.Configuration {
return config.Configuration{ return config.Configuration{
LogLevel: envStr("GTS_LOG_LEVEL", "error"), LogLevel: envStr("GTS_LOG_LEVEL", "error"),
LogTimestampFormat: "02/01/2006 15:04:05.000", LogTimestampFormat: "02/01/2006 15:04:05.000",
LogDbQueries: true, LogDbQueries: true,
ApplicationName: "gotosocial", ApplicationName: "gotosocial",
LandingPageUser: "", LandingPageUser: "",
ConfigPath: "", ConfigPath: "",
Host: "localhost:8080", Host: "localhost:8080",
AccountDomain: "localhost:8080", AccountDomain: "localhost:8080",
Protocol: "http", Protocol: "http",
BindAddress: "127.0.0.1", BindAddress: "127.0.0.1",
Port: 8080, Port: 8080,
TrustedProxies: []string{"127.0.0.1/32", "::1"}, TrustedProxies: []string{"127.0.0.1/32", "::1"},
DbType: envStr("GTS_DB_TYPE", "sqlite"), DbType: envStr("GTS_DB_TYPE", "sqlite"),
DbAddress: envStr("GTS_DB_ADDRESS", ":memory:"), DbAddress: envStr("GTS_DB_ADDRESS", ":memory:"),
DbPort: envInt("GTS_DB_PORT", 0), DbPort: envInt("GTS_DB_PORT", 0),
DbUser: envStr("GTS_DB_USER", ""), DbUser: envStr("GTS_DB_USER", ""),
DbPassword: envStr("GTS_DB_PASSWORD", ""), DbPassword: envStr("GTS_DB_PASSWORD", ""),
DbDatabase: envStr("GTS_DB_DATABASE", ""), DbDatabase: envStr("GTS_DB_DATABASE", ""),
DbTLSMode: envStr("GTS_DB_TLS_MODE", ""), DbTLSMode: envStr("GTS_DB_TLS_MODE", ""),
DbTLSCACert: envStr("GTS_DB_TLS_CA_CERT", ""), DbTLSCACert: envStr("GTS_DB_TLS_CA_CERT", ""),
DbMaxOpenConnsMultiplier: 8, DbPostgresConnectionString: envStr("GTS_DB_POSTGRES_CONNECTION_STRING", ""),
DbSqliteJournalMode: "WAL", DbMaxOpenConnsMultiplier: 8,
DbSqliteSynchronous: "NORMAL", DbSqliteJournalMode: "WAL",
DbSqliteCacheSize: 8 * bytesize.MiB, DbSqliteSynchronous: "NORMAL",
DbSqliteBusyTimeout: time.Minute * 5, DbSqliteCacheSize: 8 * bytesize.MiB,
DbSqliteBusyTimeout: time.Minute * 5,
WebTemplateBaseDir: "./web/template/", WebTemplateBaseDir: "./web/template/",
WebAssetBaseDir: "./web/assets/", WebAssetBaseDir: "./web/assets/",