Commit Graph

11 Commits

Author SHA1 Message Date
Georges-Antoine Assi
5c0bd9c418 [ROMM-2657] Safe access env vars with defaults 2025-11-15 14:54:21 -05:00
Michael Manganiello
336b3d58c1 fix: Database JSON array utils
Fix existing JSON array util `json_array_contains_value`, and add two
new utils: `json_array_contains_any` and `json_array_contains_all`.
These utils have been tested with arrays of strings and integers, on the
following database engine versions:

- PostgreSQL: 12, 13, 14, 15, 16, 17, 18
- MySQL: 8.0, 8.4, 9.0, 9.4
- MariaDB: 10.5, 10.6, 10.11, 11.4, 11.8, 12.0
2025-09-08 21:39:46 -03:00
Zurdi
881a1d158d Merge pull request #1523 from jamiecounsell/fix/mysql-json-contains
Fix MySQL json_contains Error by Converting Non-String Values to JSON Strings
2025-02-02 00:19:12 +01:00
Michael Manganiello
72a0d2b12b Add isort fixes 2025-02-01 20:13:59 -03:00
Jamie Counsell
570cb6efdf refactor based on PR feedback 2025-02-01 15:20:42 -05:00
Jamie Counsell
835def23cc coerse JSON contains args to str when using mysql 2025-01-21 13:54:04 -05:00
Michael Manganiello
6b9ff574f8 misc: Add typehints to safe type conversion functions 2025-01-11 23:18:09 -03:00
Georges-Antoine Assi
aacad9c697 [HOTFIX] Safe cast values to int for first_release_date 2025-01-11 19:37:39 -05:00
Georges-Antoine Assi
b4b0d3fb85 [HOTFIX] Safe cast values to float 2025-01-11 19:22:31 -05:00
Michael Manganiello
7825bce7b8 fix: Use proper JSON contains function for PostgreSQL
Fix `json_array_contains_value` function to use the `@>` operator for
checking if a JSON array contains a value in PostgreSQL. This is
necessary because the `has_key` function only works for string values.

Also, remove `get_rom_collections` method, as it was doing the same
thing as `get_collections_by_rom_id`.

Fixes #1441.
2025-01-08 21:07:01 -03:00
Michael Manganiello
3f4a36a5ce feat: PostgreSQL compatibility
This change introduces PostgreSQL compatibility, by implementing the
following changes:

* Use `JSONB` instead of `JSON` for PostgreSQL databases. This is
  achieved by creating a custom `CustomJSON` type that uses `JSONB` on
  PostgreSQL and `JSON` on other databases, leveraging the variant
  mechanism of SQLAlchemy.
* Add `is_postgresql` function to check if the current database is
  PostgreSQL. Commonly used for migrations, but can be used to determine
  how to build queries based on the database engine.
* Add `json_array_contains_value` function to check if a JSON array
  includes a specific value. This function is needed as it's
  engine-specific.

Support for PostgreSQL is on a best-effort basis, and it relies on the
community for continued support and testing. The project's main database
is MariaDB.

Closes #667.
2024-12-31 12:36:33 -03:00