Skip to content

Commit

Permalink
infra: make clickhouse work with env URL
Browse files Browse the repository at this point in the history
Signed-off-by: Arnav Gupta <[email protected]>
  • Loading branch information
championswimmer committed Jan 28, 2024
1 parent a5f63c3 commit f80e13d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/onepixel_backend.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion onepixel.local.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ DB_DIALECT=postgres
DATABASE_URL="host=postgres user=postgres password=postgres dbname=onepixel port=5432 sslmode=disable TimeZone=UTC"
ADMIN_API_KEY="8DC4FCD4-DD71-4C18-B9C0-C38EF6790815"
JWT_SIGNING_KEY="ECkLlR74HWIZTG4GAFsmBFoqO7Nr30Bc"
JWT_DURATION_DAYS=90
JWT_DURATION_DAYS=90
EVENTDB_URL="clickhouse://clickhouse:[email protected]:9000/onepixel?dial_timeout=10s&read_timeout=20s"
12 changes: 12 additions & 0 deletions public_html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="./style.css" />


<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-51J34YD93D"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-51J34YD93D');
</script>

</head>

<body>
Expand Down
6 changes: 6 additions & 0 deletions src/config/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var DBLogging string
var DBDialect string
var DBUrl string

var EventDBUrl string

var Port string
var MainHost string
var AdminHost string
Expand All @@ -34,6 +36,10 @@ func init() {
os.Getenv("DATABASE_PRIVATE_URL"),
os.Getenv("DATABASE_URL"),
)
EventDBUrl, _ = lo.Coalesce(
os.Getenv("EVENTDB_PRIVATE_URL"),
os.Getenv("EVENTDB_URL"),
)
Port = os.Getenv("PORT")
MainHost = os.Getenv("MAIN_SITE_HOST")
AdminHost = os.Getenv("ADMIN_SITE_HOST")
Expand Down
3 changes: 1 addition & 2 deletions src/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ func GetAppDB() (*gorm.DB, error) {
func GetEventsDB() (*gorm.DB, error) {
createEventsDbOnce.Do(func() {

dsn := "clickhouse://clickhouse:[email protected]:9000/onepixel?dial_timeout=10s&read_timeout=20s"
applogger.Warn("Events: Using clickhouse db")
eventsDb = lo.Must(gorm.Open(clickhouse.Open(dsn), getGormConfig()))
eventsDb = lo.Must(gorm.Open(clickhouse.Open(config.EventDBUrl), getGormConfig()))

lo.Must0(eventsDb.AutoMigrate(&models.EventRedirect{}))
})
Expand Down
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
func main() {
// Initialize the database
appDb := lo.Must(db.GetAppDB())
//_ = lo.Must(db.GetEventsDB())
_ = lo.Must(db.GetEventsDB())

// Create the app
adminApp := server.CreateAdminApp()
Expand Down

0 comments on commit f80e13d

Please sign in to comment.