Sqlite: lease one pooled connection for pragmas plus a transaction (safe table rebuilds)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 15/100
Direzione di ricerca
This is a design request for a new platform API, not a located edit: the proposed Sqlite.with_connection! would hand one pooled connection to a block exposing execute!, query_many! and begin!, then reset open-time settings such as PRAGMA foreign_keys = ON on return. Start by reading how the basic-webserver Sqlite pool leases connections and where the foreign-keys pragma is applied at open time, then how Sqlite.begin! currently acquires its connection. Done looks like a lease that keeps the pragma and the transaction on one connection, plus a test that rebuilds a table with foreign keys off.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
Please give a way to lease one pooled connection for a short block. Inside the block, the code can send connection-level statements and then a transaction, all on that same connection. A possible form:
Sqlite.with_connection! : Sqlite.Db, (Sqlite.Connection => Try(a, e)) => Try(a, [Sqlite(Sqlite.QueryError), ..e])
# Sqlite.Connection has execute!, query_many! and begin! (a Sqlite.Transaction on this connection)
When the block ends, the platform could reset what it set at open time (for example PRAGMA foreign_keys = ON) before it returns the connection to the pool.
Why it is needed
Some SQLite schema migrations must rebuild a table: create a new table, copy the rows, drop the old table, rename the new one. The SQLite docs say to do this with foreign keys off:
PRAGMA foreign_keys = OFF; -- a no-op inside a transaction, so it must come before BEGIN
BEGIN;
-- create, copy, drop, rename
PRAGMA foreign_key_check;
COMMIT;
PRAGMA foreign_keys = ON;
PRAGMA foreign_keys is per connection. On the basic-webserver pool, the pragma and the later Sqlite.begin! can lease different connections. The platform also turns foreign keys on for every pooled connection. So in the transaction, foreign keys are always on. A migration runner must then choose one of two options:
| Option | Result |
|---|---|
| Rebuild with foreign keys on | DROP TABLE runs the ON DELETE CASCADE actions of the child tables and deletes their rows. This loses data |
| Refuse the rebuild | Safe. The migration must run from another tool before the server starts |
A migration runner takes the safe option today. With a connection lease, it could run every migration inside the server's init!.
Current workaround
Apply SQLite migrations with a separate one-connection program (for example on basic-cli) before the server starts. Other migrations and read-only schema checks work from the server today.
Priority
Not a blocker. The workaround is one more step in deployment. This is a wanted feature: it lets a basic-webserver app apply all of its own migrations at start, safely. The same lease could also help other per-connection settings that a library cannot apply reliably on a pool today.
- Lingua principale
- HTML
- Stelle
- 110
- Fork
- 25
- Merge medio
- 18h 28m
- PR unite (30g)
- 16
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di roc-lang/basic-webserver
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
roc-lang/basic-webserver#277 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
roc-lang/basic-webserver#274 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
roc-lang/basic-webserver#272 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
roc-lang/basic-webserver#265 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 28/100
roc-lang/basic-webserver#231 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di roc-lang/basic-webserver
Issue simili
-
cleanup follow-up
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 1 giorno
-
flakybot: issue priority: p2 type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
GoogleCloudPlatform/cloud-sql-nodejs-connector#658 ·
I maintainer di solito rispondono entro 1 giorno
-
factory:subtask
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
ConduitIO/conduit-connector-postgres#491 ·
I maintainer di solito rispondono entro 1 giorno
-
SUM over a union column should skip an undefined slot, not throw ArrayIndexOutOfBoundsExceptionApertaexpression engine unshaved-yak
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno