diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-11 18:29:55 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-11 18:32:28 +0200 |
commit | b689a85b9df4c4fa64f243e27c7498693d0496a4 (patch) | |
tree | 94f5405c1738d3337ed0af02e513650d1e0d0457 | |
parent | sqlite: rename SQL schema variables (diff) | |
download | cimple-b689a85b9df4c4fa64f243e27c7498693d0496a4.tar.gz cimple-b689a85b9df4c4fa64f243e27c7498693d0496a4.zip |
sqlite: make some identifiers more readable
-rw-r--r-- | src/sqlite/v01.sql | 8 | ||||
-rw-r--r-- | src/storage_sqlite.c | 7 | ||||
-rw-r--r-- | test/py/lib/db.py | 2 |
3 files changed, 8 insertions, 9 deletions
diff --git a/src/sqlite/v01.sql b/src/sqlite/v01.sql index acde438..c64a55f 100644 --- a/src/sqlite/v01.sql +++ b/src/sqlite/v01.sql @@ -18,10 +18,10 @@ INSERT INTO cimple_run_status(id, label) VALUES (2, 'finished'); CREATE TABLE cimple_runs ( id INTEGER PRIMARY KEY, status INTEGER NOT NULL, - ec INTEGER NOT NULL, + exit_code INTEGER NOT NULL, output BLOB NOT NULL, repo_id INTEGER NOT NULL, - rev TEXT NOT NULL, + repo_rev TEXT NOT NULL, FOREIGN KEY (status) REFERENCES cimple_run_status(id), FOREIGN KEY (repo_id) REFERENCES cimple_repos(id) ON DELETE CASCADE ON UPDATE CASCADE @@ -30,7 +30,7 @@ CREATE TABLE cimple_runs ( CREATE INDEX cimple_runs_index_status ON cimple_runs(status); CREATE INDEX cimple_runs_index_repo_id ON cimple_runs(repo_id); -CREATE VIEW cimple_runs_readable AS - SELECT run.id, status.label, run.ec, run.output, repo.url, run.rev FROM cimple_runs AS run +CREATE VIEW cimple_runs_view(id, status, exit_code, output, repo_url, repo_rev) AS + SELECT run.id, status.label, run.exit_code, run.output, repo.url, run.repo_rev FROM cimple_runs AS run INNER JOIN cimple_run_status as status ON run.status = status.id INNER JOIN cimple_repos as repo ON run.repo_id = repo.id; diff --git a/src/storage_sqlite.c b/src/storage_sqlite.c index 8bee6f1..8973fd9 100644 --- a/src/storage_sqlite.c +++ b/src/storage_sqlite.c @@ -206,9 +206,9 @@ static int storage_sqlite_prepare_statements(struct storage_sqlite *storage) static const char *const fmt_repo_insert = "INSERT INTO cimple_repos(url) VALUES (?) ON CONFLICT(url) DO NOTHING;"; static const char *const fmt_run_insert = - "INSERT INTO cimple_runs(status, ec, output, repo_id, rev) VALUES (?, -1, x'', ?, ?) RETURNING id;"; + "INSERT INTO cimple_runs(status, exit_code, output, repo_id, repo_rev) VALUES (?, -1, x'', ?, ?) RETURNING id;"; static const char *const fmt_run_finished = - "UPDATE cimple_runs SET status = ?, ec = ?, output = ? WHERE id = ?;"; + "UPDATE cimple_runs SET status = ?, exit_code = ?, output = ? WHERE id = ?;"; int ret = 0; @@ -462,8 +462,7 @@ free_url: int storage_sqlite_get_run_queue(struct storage *storage, struct run_queue *queue) { static const char *const fmt = - "SELECT cimple_runs.id, cimple_repos.url, cimple_runs.rev FROM cimple_runs" - " INNER JOIN cimple_repos ON cimple_runs.repo_id = cimple_repos.id WHERE cimple_runs.status = ?;"; + "SELECT id, repo_url, repo_rev FROM cimple_runs_view WHERE status = ?;"; sqlite3_stmt *stmt; int ret = 0; diff --git a/test/py/lib/db.py b/test/py/lib/db.py index 9fddbf5..133a627 100644 --- a/test/py/lib/db.py +++ b/test/py/lib/db.py @@ -26,5 +26,5 @@ class Database: def get_all_runs(self): with self.get_cursor() as cur: - cur.execute('SELECT * FROM cimple_runs_readable') + cur.execute('SELECT * FROM cimple_runs_view') return cur.fetchall() |