home to your local SPACEGIRL 💫 arimelody.space
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fixed issues with first-time setup, added config.db.port

+26 -12
+6 -2
controller/migrator.go
··· 20 20 ) 21 21 22 22 oldDBVersion := 0 23 - 24 - err := db.Get(&oldDBVersion, "SELECT MAX(version) FROM schema_version") 23 + schemaVersionCount := 0 24 + err := db.Get(&schemaVersionCount, "SELECT COUNT(*) FROM schema_version") 25 25 if err != nil { panic(err) } 26 + if schemaVersionCount > 0 { 27 + err := db.Get(&oldDBVersion, "SELECT MAX(version) FROM schema_version") 28 + if err != nil { panic(err) } 29 + } 26 30 27 31 for oldDBVersion < DB_VERSION { 28 32 switch oldDBVersion {
+11
global/config.go
··· 13 13 type ( 14 14 dbConfig struct { 15 15 Host string `toml:"host"` 16 + Port int64 `toml:"port"` 16 17 Name string `toml:"name"` 17 18 User string `toml:"user"` 18 19 Pass string `toml:"pass"` ··· 42 43 config := config{ 43 44 BaseUrl: "https://arimelody.me", 44 45 Port: 8080, 46 + DB: dbConfig{ 47 + Host: "127.0.0.1", 48 + Port: 5432, 49 + User: "arimelody", 50 + Name: "arimelody", 51 + }, 45 52 } 46 53 47 54 data, err := os.ReadFile(configFile) ··· 80 87 if env, has := os.LookupEnv("ARIMELODY_DATA_DIR"); has { config.DataDirectory = env } 81 88 82 89 if env, has := os.LookupEnv("ARIMELODY_DB_HOST"); has { config.DB.Host = env } 90 + if env, has := os.LookupEnv("ARIMELODY_DB_PORT"); has { 91 + config.DB.Port, err = strconv.ParseInt(env, 10, 0) 92 + if err != nil { return errors.New("ARIMELODY_DB_PORT: " + err.Error()) } 93 + } 83 94 if env, has := os.LookupEnv("ARIMELODY_DB_NAME"); has { config.DB.Name = env } 84 95 if env, has := os.LookupEnv("ARIMELODY_DB_USER"); has { config.DB.User = env } 85 96 if env, has := os.LookupEnv("ARIMELODY_DB_PASS"); has { config.DB.Pass = env }
+8 -3
main.go
··· 30 30 func main() { 31 31 fmt.Printf("made with <3 by ari melody\n\n") 32 32 33 + // TODO: refactor `global` to `AppState` 34 + // this should contain `Config` and `DB`, and be passed through to all 35 + // handlers that need it. it's better than weird static globals everywhere! 36 + 33 37 // initialise database connection 34 38 if global.Config.DB.Host == "" { 35 39 fmt.Fprintf(os.Stderr, "FATAL: db.host not provided! Exiting...\n") ··· 52 56 global.DB, err = sqlx.Connect( 53 57 "postgres", 54 58 fmt.Sprintf( 55 - "host=%s user=%s dbname=%s password='%s' sslmode=disable", 59 + "host=%s port=%d user=%s dbname=%s password='%s' sslmode=disable", 56 60 global.Config.DB.Host, 61 + global.Config.DB.Port, 57 62 global.Config.DB.User, 58 63 global.Config.DB.Name, 59 64 global.Config.DB.Pass, ··· 319 324 os.Exit(1) 320 325 } 321 326 322 - fmt.Fprintf(os.Stdout, "No accounts exist! Generated invite code: " + string(invite.Code) + "\nUse this at %s/admin/register.\n", global.Config.BaseUrl) 327 + fmt.Printf("No accounts exist! Generated invite code: %s\n", invite.Code) 323 328 } 324 329 325 330 // delete expired invites ··· 331 336 332 337 // start the web server! 333 338 mux := createServeMux() 334 - fmt.Printf("Now serving at http://127.0.0.1:%d\n", global.Config.Port) 339 + fmt.Printf("Now serving at %s:%d\n", global.Config.BaseUrl, global.Config.Port) 335 340 log.Fatal( 336 341 http.ListenAndServe(fmt.Sprintf(":%d", global.Config.Port), 337 342 global.HTTPLog(global.DefaultHeaders(mux)),
+1 -7
schema_migration/000-init.sql
··· 1 - CREATE SCHEMA arimelody; 2 - 3 - -- Schema verison 4 - CREATE TABLE arimelody.schema_version ( 5 - version INTEGER PRIMARY KEY, 6 - applied_at TIMESTAMP DEFAULT current_timestamp 7 - ); 1 + CREATE SCHEMA IF NOT EXISTS arimelody; 8 2 9 3 -- 10 4 -- Tables