-
-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Postgres support #5355
base: develop
Are you sure you want to change the base?
Postgres support #5355
Conversation
Fix insert return id
Fix blobs
Blob test fixes
pkg/sqlite/database_postgres.go
Outdated
if disableForeignKeys { | ||
_, err = conn.Exec("SET session_replication_role = replica;") | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("conn.Exec(): %w", err) | ||
} | ||
} | ||
if !writable { | ||
_, err = conn.Exec("SET default_transaction_read_only = ON;") | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("conn.Exec(): %w", err) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest not supporting "disable foreign key" and "read-only" in Postgres in the application layer.
They exist for SQLite because of limitations in the DB, such as some messiness with foreign keys. For connecting to Postgres as read-only, I'd strongly recommend that admins create a user with read-only permissions to the DB, rather than doing that in Stash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this is ugly and should be removed.
But that would necessitate adding another connection string.
Im gonna have to think about it.
Or simply add "database_string_ro" 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you absolutely need to tell Stash to make this RO, you could add a query stirng parameter to the connection string.
Something like ?readonly=1
to the URL... and then we remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial review/feedback from me
performer_id integer, | ||
scene_id integer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be non-nullable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ehh, they are written like that in the original schema, and they are foreign keys that reference other tables.
So i think its fine
i fix bugs, therefore i am
Sort by nulls last fix for tests. UUID handler Switch strftime for native postgresql types Fix bug in performer studio filter
LIKE in SQLITE is case insensetive by default, where its SENSETIVE in postgres. Postgres has ILIKE which is insensitive, we should use that
Hello, this is an attempt at implementing postgres support.
If you want to test this branch, you can add these changes to your config.yml:
There are alot of changes, highlights:
lastInsertId is a SQLite specific feature, other databases need you to specify "returning id". Which our version of SQLite supports, but goqu doesnt mark it as supported, so we create our own custom definition.
Call regexp as a function, as postgresql doesnt support named operators.
Some particularly egregious changes or missing things are are:
We create new "databases" for this, test this functionality.
There is no script for migrating from sqlite to postgresql.
We have PGSQL_TEST string which should be able to test postgresql,
PGSQL_TEST='postgresql://username:password@localhost/dbname_for_testing' go test -tags "sqlite_stat4 sqlite_math_functions integration" ./...
There are probably bugs i haven't found, but it works for both sqlite and postgresql in my testing.
In particular fingerprints where changed from blob to text, since its mostly strings or numbers, and you cannot insert numbers into bytea (postgresql blob), where you could with text.
I dont know that timestamp (postgresql) follows the same rules as datetime (sqlite).
Also others.
For supporting postgresql we use rebind to convert unnamed parameters (the ?), to named ($1 etc.).
This should theoretically always work, but is ugly.
While i have create the extension, it does not automatically install, and i dont know that its cross-compatible across postgresql versions.
To look at (help me):
Postgresql C/CGo extension to support missing functionality (basename, phash_distance, regexp):
https://github.com/NodudeWasTaken/stash_pge
You can use dbeaver for testing the database, its nice for browsing various databases like sqlite and postgresql.
To support disable foreign keys we do (if anybody knows a better way, let me know):
"SET session_replication_role = replica;"
which requires extra postgres user permissions, just a note.
This is mainly a request for comments, or help, mainly help finishing this.
Fixes #3892