46 Commits

Author SHA1 Message Date
Sybren A. Stüvel
ddced5a823 Transition from ex-GORM structs to sqlc structs (4/5)
Replace old used-to-be-GORM datastructures (#104305) with sqlc-generated
structs. This also makes it possible to use more specific structs that
are more taylored to the specific queries, increasing efficiency.

This commit deals with the worker sleep schedule.

Functional changes are kept to a minimum, as the API still serves the
same data.

Because this work covers so much of Flamenco's code, it's been split up
into different commits. Each commit brings Flamenco to a state where it
compiles and unit tests pass. Only the result of the final commit has
actually been tested properly.

Ref: #104343
2024-12-04 14:00:19 +01:00
Sybren A. Stüvel
84f93e7502 Transition from ex-GORM structs to sqlc structs (2/5)
Replace old used-to-be-GORM datastructures (#104305) with sqlc-generated
structs. This also makes it possible to use more specific structs that
are more taylored to the specific queries, increasing efficiency.

This commit mostly deals with workers, including the sleep schedule and
task scheduler.

Functional changes are kept to a minimum, as the API still serves the
same data.

Because this work covers so much of Flamenco's code, it's been split up
into different commits. Each commit brings Flamenco to a state where it
compiles and unit tests pass. Only the result of the final commit has
actually been tested properly.

Ref: #104343
2024-12-04 14:00:13 +01:00
Sybren A. Stüvel
94d71bc3c9 Transition from ex-GORM structs to sqlc structs (1/5)
Replace old used-to-be-GORM datastructures (#104305) with sqlc-generated
structs. This also makes it possible to use more specific structs that
are more taylored to the specific queries, increasing efficiency.

This commit covers job blocklists and last-rendered images.

Functional changes are kept to a minimum, as the API still serves the
same data.

Because this work covers so much of Flamenco's code, it's been split up
into different commits. Each commit brings Flamenco to a state where it
compiles and unit tests pass. Only the result of the final commit has
actually been tested properly.

Ref: #104343
2024-12-04 14:00:07 +01:00
Sybren A. Stüvel
7f37c16a8d Add 'index in job' number to tasks
Number the tasks in a job, indicating their creation order. This gives the
web interface something to sort on that doesn't change on task updates.
2024-11-09 23:07:23 +01:00
Sybren A. Stüvel
816046663e Manager: remove GORM from database interface
Remove all calls to GORM from the database interface code.

Ref: #104305
2024-09-26 22:58:11 +02:00
Sybren A. Stüvel
f1a72903a0 Manager: rename sql/integrity.go to sql/pragma.go
The file contains pragma queries only, and I'm about to add more pragma
queries that aren't related to database integrity.
2024-09-26 22:43:30 +02:00
Sybren A. Stüvel
29419cb30e Manager: convert final sleep schedule queries to sqlc
Ref: #104305
2024-09-26 22:26:30 +02:00
Sybren A. Stüvel
2cc049c52c Manager: convert final 'last rendered' queries to sqlc
Ref #104305
2024-09-26 21:26:38 +02:00
Sybren A. Stüvel
d43947898d Manager: replace final job-related queries with sqlc
Ref: #104305
2024-09-26 21:20:01 +02:00
Sybren A. Stüvel
71bbaaeae0 Manager; convert fetching of sleep schedules to sqlc
This also corrects the sleep schedule schema to actually store the
`is_active` field as `boolean` (it was `numeric`, which is the same
underlying field type in SQLite, but produces a different struct field
in the sqlc-generated Go code).

Ref: #104305
2024-09-18 21:11:54 +02:00
Sybren A. Stüvel
777a417cc0 Manager: convert timeout checks to sqlc
Ref: #104305
2024-09-18 20:39:03 +02:00
Sybren A. Stüvel
ebf1693a7c Manager: convert busy-timeout query to sqlc
Ref: #104305
2024-09-18 16:49:01 +02:00
Sybren A. Stüvel
4bd6dc64b0 Manager: convert worker tag queries to sqlc
Ref: #104305
2024-09-18 16:07:43 +02:00
Sybren A. Stüvel
35313477a0 Manager; convert QueryJobTaskSummaries and SummarizeJobStatuses to sqlc
Ref: #104305
2024-09-18 14:54:49 +02:00
Sybren A. Stüvel
cda0b916fb Manager: replace queryJobs with fetchJobs operation
See the previous two commits for the motivation.
2024-09-18 14:29:15 +02:00
Sybren A. Stüvel
3a872370df Manager: convert job blocklist queries from GORM to sqlc
Ref: #104305
2024-09-18 10:40:29 +02:00
Sybren A. Stüvel
a015408486 Manager: convert foreign key integrity check to sqlc
Ref: #104305
2024-09-18 10:17:31 +02:00
Sybren A. Stüvel
476d4059bf Manager: convert pragma foreign key command to sqlc
No functional changes.

Ref: #104305
2024-09-18 10:17:27 +02:00
Sybren A. Stüvel
af6f7103c4 Manager: convert DB integrity check to sqlc
Convert the database integrity check from GORM to sqlc.

No functional changes.

Ref: #104305
2024-09-18 10:17:08 +02:00
Sybren A. Stüvel
1f7cab0ef2 Manager: convert job blocklist management queries to sqlc
Convert most of the job blocklist queries from GORM to sqlc. The management
functions (add worker, remove worker, clear list, fetch list) have been
converted.
2024-08-02 12:50:17 +02:00
Sybren A. Stüvel
3b2b5c47f3 Manager: convert FetchWorkerTask() from gorm to sqlc
Ref: #104305

No functional changes
2024-07-02 10:16:41 +02:00
Sybren A. Stüvel
842d1ab9a4 Manager: convert storing authored jobs from gorm to sqlc
Convert the creation of new jobs & tasks in the database (which happens
by storing the 'authored job' + its tasks) from gorm to sqlc.
2024-06-30 23:31:28 +02:00
Sybren A. Stüvel
bfe47ea394 Manager: convert task scheduler from gorm to sqlc
Convert the task scheduler from gorm to sqlc. This makes the query
considerably easier to read.

No functional changes intended.
2024-06-30 21:18:08 +02:00
Sybren A. Stüvel
374a8c0a6f Manager: remove introduction comments from the query SQL
Remove the introductionary comments from `query_jobs.sql` and
`query_workers.sql`. Sqlc got confused by this, and placed them in the
wrong (well, not-intended-by-me) place in the generated Go code.

No functional changes.
2024-06-08 21:35:41 +02:00
Sybren A. Stüvel
5a31336efb Manager: Convert 'last-rendered' to sqlc
Convert 'last-rendered' to sqlc. The query is slightly suboptimal.
There's a bug in sqlc: the `ON CONFLICT DO UPDATE` clause is generated
incorrectly. See https://github.com/sqlc-dev/sqlc/issues/3334 for more
info.
2024-06-08 21:30:00 +02:00
Sybren A. Stüvel
7a9f809c43 Manager: convert more worker functions to sqlc
No functional changes.
2024-05-28 18:20:15 +02:00
Sybren A. Stüvel
9a229a7b8f Manager: Convert CreateWorker to sqlc
No functional changes.
2024-05-28 18:20:07 +02:00
Sybren A. Stüvel
0c4240ec3a Manager: make some db fields boolean instead of smallint
Turn `workers.lazy_status_request` and `workers.can_restart` into a
`boolean`. They were `smallint` before.

Having these explicitly modeled as `boolean` will make sqlc generate the
right type for them.

No functional changes.
2024-05-28 18:15:21 +02:00
Sybren A. Stüvel
98cbe6a67d Manager: lightly polish job deletion
Tweak the logging a little bit so it's less noisy, properly warns when the
Shaman checkout dir cannot be removed, and optimise the database query
a bit (by just fetching the one field that's needed, instead of the entire
job).

Deletion still works the same.
2024-05-28 16:07:22 +02:00
Sybren A. Stüvel
79076be91b Manager: Convert task failure persistence to SQLC
No functional changes.
2024-05-28 16:07:22 +02:00
Sybren A. Stüvel
a99e68ec99 Manager: Convert TaskTouchedByWorker to sqlc
No functional changes.
2024-05-28 16:07:21 +02:00
Sybren A. Stüvel
7175bb469b Manager: Convert UpdateJobsTaskStatuses(Conditional) to sqlc
No functional changes.
2024-05-28 16:07:21 +02:00
Sybren A. Stüvel
4435633756 Manager: Convert FetchTasksOfJob() and FetchTasksOfJobInStatus() to sqlc
No functional changes.
2024-05-28 16:07:21 +02:00
Sybren A. Stüvel
4ab853da40 Manager: Convert JobHasTasksInStatus and CountTasksOfJobInStatus to sqlc
No functional changes.
2024-05-28 16:07:21 +02:00
Sybren A. Stüvel
1e327c510e Manager: Convert FetchTasksOfWorkerInStatusOfJob to sqlc
No functional changes.
2024-05-28 14:46:43 +02:00
Sybren A. Stüvel
950d661377 Manager: convert TaskAssignToWorker and FetchTasksOfWorkerInStatus to sqlc
No functional changes.
2024-05-28 14:46:43 +02:00
Sybren A. Stüvel
dcca9aef03 Manager: convert db.SaveTaskActivity() to SQLC
No functional changes.
2024-05-28 14:46:42 +02:00
Sybren A. Stüvel
a9be729e59 Manager: Convert db.SaveTaskStatus() to SQLC
No functional changes.
2024-05-28 14:46:42 +02:00
Sybren A. Stüvel
a54972ddd0 Manager: Convert db.SaveTask() to SQLC
No functional changes.
2024-05-28 14:46:42 +02:00
Sybren A. Stüvel
f632f2dbb6 SQLC: upgrade to 1.26.0
Doesn't change anything function in the generated code, just the version
numbers & handling of empty comments in the query file.
2024-05-28 14:46:42 +02:00
Sybren A. Stüvel
c1cdff567e Manager: Convert FetchTask to sqlc
This is a bit more work than other queries, as it also breaks apart the
fetching of the job and the worker into separate ones. In other words,
internally the persistence layer API changes.
2024-05-28 14:46:42 +02:00
Sybren A. Stüvel
7b72d0ca43 Refactor: move jobs-related queries to queries_jobs.sql
This makes it easier to later also create `query_workesr.sql`,
`query_meta.sql` etc. so that the sqlc-generated code can follow the
same subdivision as the persistence service code itself.

No functional changes.
2024-03-03 23:27:55 +01:00
Sybren A. Stüvel
b102b73a1f Refactor: convert more job functions to sqlc
No functional changes.
2024-03-03 23:23:51 +01:00
Sybren A. Stüvel
1ac796d0d8 Refactor: Manager: remove unused query from queries.sql
No functional changes.
2024-03-03 22:42:37 +01:00
Sybren A. Stüvel
3fbb3cde34 Manager: SQLC rename Uuid to UUID
No functional changes.
2024-03-03 20:54:43 +01:00
Sybren A. Stüvel
c046094880 Manager: start replacing GORM with SQLC
GORM has certain downsides:

- Code-first approach, where queries have to be translated to the Go code
  required to execute them.
- GORM comes with its own SQLite implementation, which doesn't provide an
  on-connect callback. This means that new connections cannot correctly
  enable foreign key constraints, causing database consistency issues.

[SQLC](https://sqlc.dev/) solves these issues for us.

This commit doesn't fully replace GORM with SQLC, but introduces it for
a few queries. Once all queries have been converted, GORM can be removed
completely.
2024-03-03 20:15:39 +01:00