Sqlite: lease one pooled connection for pragmas plus a transaction (safe table rebuilds)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 15/100
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- HTML
- スター
- 110
- フォーク
- 25
- 平均マージ
- 18時間 28分
- マージ済み PR(30日)
- 16
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
roc-lang/basic-webserver のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
roc-lang/basic-webserver#277 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
roc-lang/basic-webserver#274 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
roc-lang/basic-webserver#272 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
roc-lang/basic-webserver#265 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 28/100
roc-lang/basic-webserver#231 ·
メンテナーはふだん 1 日以内に返信
roc-lang/basic-webserver の issue をすべて見る
似ている issue
-
cleanup follow-up
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 1 日以内に返信
-
flakybot: issue priority: p2 type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
GoogleCloudPlatform/cloud-sql-nodejs-connector#658 ·
メンテナーはふだん 1 日以内に返信
-
factory:subtask
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
ConduitIO/conduit-connector-postgres#491 ·
メンテナーはふだん 1 日以内に返信
-
SUM over a union column should skip an undefined slot, not throw ArrayIndexOutOfBoundsExceptionオープンexpression engine unshaved-yak
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信