GithubHelp home page GithubHelp logo

PostgreSQL support about server HOT 5 OPEN

traggo avatar traggo commented on August 16, 2024 7
PostgreSQL support

from server.

Comments (5)

jmattheis avatar jmattheis commented on August 16, 2024 1

It would be nice to have to support postgres or mysql but I don't think it is worth the development effort. SQLite will work nicely with small userbases and thats exactly for what it was designed (:.

from server.

Skeen avatar Skeen commented on August 16, 2024 1

Please reconsider this @jmattheis.

While SQLite does indeed work nicely with small userbases and all, some users may already have managed database infrastructure in place which they wish to use, for instance because it provides proper backup, etc.

I was able to get Traggo running under Postgres by with minimal changes:

diff --git a/model/all.go b/model/all.go
index 27d2378..a5893ab 100644
--- a/model/all.go
+++ b/model/all.go
@@ -3,8 +3,8 @@ package model
 // All returns all schema instances.
 func All() []interface{} {
        return []interface{}{
-               new(TagDefinition),
                new(User),
+               new(TagDefinition),
                new(Device),
                new(TimeSpan),
                new(TimeSpanTag),

This makes the migration work, by ensuring that inter-relation dependencies are ordered.
As the code stands now TagDefinition depends on User which makes the automigration fail on Postgres.

diff --git a/model/device.go b/model/device.go
index 589ca63..ed8d594 100644
--- a/model/device.go
+++ b/model/device.go
@@ -14,7 +14,7 @@ type Device struct {
        Name      string
        UserID    int `gorm:"type:int REFERENCES users(id) ON DELETE CASCADE"`
        CreatedAt time.Time
-       Type      DeviceType
+       Type      DeviceType `gorm:"type:bytea"`
        ActiveAt  time.Time
 }

This makes the device lookups work as the code seem to expect byte[] access.
I expected it to work out of the box, but it does not on Postgres.
I tried to use Gorm's bytes type, but not in fact work for Postgres, it yields an error that bytes is not a known type in postgres, so the appropriate type would be bytea.

This last change is however destructive to SQLite support as SQLite does not have a bytea type.
I don't know Gorm, so I am not sure how to specify a different type for each database dialect.

from server.

jmattheis avatar jmattheis commented on August 16, 2024

It could be done similar to https://github.com/gotify/server/blob/master/database/database.go#L70, I'm open to accept a PR for this. But please make sure, the statistics endpoint for calculating the dashboard aggregation does work https://github.com/traggo/server/blob/master/statistics/summary.go#L38

from server.

alonsomoya avatar alonsomoya commented on August 16, 2024

I'm indeed experiencing concurrency issues while deploying traggo in kubernetes. With SQLite & CIFS, and the DB being locked even with a simple pod/container, so I could not make traggo to work with PersistentVolumes.
Did postgres support got implemented in the meanwhile? I would surely be interested

from server.

jmattheis avatar jmattheis commented on August 16, 2024

No, not implemented and likely won't in the future. See explanation in my first comment.

from server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.