this repo has no description
0
fork

Configure Feed

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

db config: allow previous sqlite= and postgres= style strings

Based on feedback from why

+19 -1
+19 -1
cmd/gosky/util/util.go
··· 150 150 return &auth, nil 151 151 } 152 152 153 + // Supports both previous "dbtype=" prefixed DSNs, and URI-style database config strings, for both sqlite and postgresql. 154 + // 155 + // Examples: 156 + // - "sqlite=dir/file.sqlite" 157 + // - "sqlite://file.sqlite" 158 + // - "postgres=host=localhost user=postgres password=password dbname=pdsdb port=5432 sslmode=disable" 159 + // - "postgresql://postgres:password@localhost:5432/pdsdb?sslmode=disable" 153 160 func SetupDatabase(dburl string) (*gorm.DB, error) { 154 161 var dial gorm.Dialector 155 162 // NOTE(bnewbold): might also handle file:// as sqlite, but let's keep it ··· 162 169 os.MkdirAll(filepath.Dir(sqliteSuffix), os.ModePerm) 163 170 } 164 171 dial = sqlite.Open(sqliteSuffix) 165 - } else if strings.HasPrefix(dburl, "postgresql://") { 172 + } else if strings.HasPrefix(dburl, "sqlite=") { 173 + sqliteSuffix := dburl[len("sqlite="):] 174 + // if this isn't ":memory:", ensure that directory exists (eg, if db 175 + // file is being initialized) 176 + if !strings.Contains(sqliteSuffix, ":?") { 177 + os.MkdirAll(filepath.Dir(sqliteSuffix), os.ModePerm) 178 + } 179 + dial = sqlite.Open(sqliteSuffix) 180 + } else if strings.HasPrefix(dburl, "postgresql://") || strings.HasPrefix(dburl, "postgres://") { 166 181 // can pass entire URL, with prefix, to gorm driver 167 182 dial = postgres.Open(dburl) 183 + } else if strings.HasPrefix(dburl, "postgres=") { 184 + dsn := dburl[len("postgres="):] 185 + dial = postgres.Open(dsn) 168 186 } else { 169 187 // TODO(bnewbold): this might print password? 170 188 return nil, fmt.Errorf("unsupported or unrecognized DATABASE_URL value: %s", dburl)