fix(database): bos veritabaninda kurulum ERROR 1005 ile kiriliyordu - #3
fix(database): bos veritabaninda kurulum ERROR 1005 ile kiriliyordu
#3ersinkoc wants to merge 1 commit into
Conversation
Kok neden: repoda hicbir yerde CREATE TABLE users yoktu; schema.sql'in ilk tablosu (departments) manager_id uzerinden users(id)'ye FK iceriyor ve bolum 10 yalnizca ALTER ediyordu. README'nin belgelenmis kurulum akisi (schema.sql + seed.sql) bos veritabaninda ERROR 1005 (errno 150) ile kiriliyordu. Ikinci yuzey: seed.sql admin@riskops.local kullanıcısını yalnizca UPDATE ediyor, INSERT eden yoktu - kurulum sonunda belgelenmis giris hesabi (Admin123456, ilk giriste degisim zorunlu) olusmuyordu. Cozum: - schema.sql bolum 0: CREATE TABLE IF NOT EXISTS users (temel kolonlar; role ENUM varsayilan 'viewer' - en az yetki). Bolum 10'daki IF NOT EXISTS ALTER'lar yukseltme yolu olarak aynen kaldi (idempotent). - seed.sql: belgelenmis ilk admin INSERT IGNORE ile eklenir (bcrypt, must_change_password=1); mevcut UPDATE onu IT departmanina baglar. Kanit: round-owned proof-script GERCEK schema.sql + seed.sql dosyalarini bosaltilmis karalama veritabanina calistirdi: oncesinde FAIL (statement CodeByPinar#4: ERROR 1005 departments), sonrasi PASS (10 tablo, admin dogrulandi, password_verify('Admin123456') true). Dayanikli regresyon testi tools/fresh_bootstrap_test.php eklendi (yerel MariaDB ister; bos veritabaninda kurulum + ust uste tekrar calismanin idempotentligi; karalama veritabanini kendisi dusurur): 13 OK / 0 FAIL. Mevcut kurulumda geriye donuk uyumluluk: duzeltilmis schema+seed canli veritabanina tekrar uygulandi - temiz no-op. php tools/smoke_test.php: 58 OK / 1 FAIL (yalnizca /var/www/riskops yerlesim yolu onaylamasi; islevsel tum kontroller geciyor).
There was a problem hiding this comment.
4 issues found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tools/fresh_bootstrap_test.php">
<violation number="1" location="tools/fresh_bootstrap_test.php:31">
P2: The documented Ubuntu setup authenticates MariaDB root through `sudo mysql`, but this test forces TCP root login with a committed password that setup never creates. Read the connection credentials and socket from the environment, or use the configured test database account.</violation>
<violation number="2" location="tools/fresh_bootstrap_test.php:104">
P1: When a developer already has a database named `riskops_bootstrap_test`, this test irreversibly deletes it before running. Generate a unique scratch database per run or refuse to proceed when the fixed name exists.</violation>
<violation number="3" location="tools/fresh_bootstrap_test.php:141">
P2: This check labeled IT only verifies that `department_id` is non-null, so a seed regression linking the admin to Finance or another department still passes. Assert the joined department code is `IT`.</violation>
<violation number="4" location="tools/fresh_bootstrap_test.php:165">
P3: When schema.sql fails (the exact regression this test guards against), later `$pdo->query(...)->fetch()` calls on `users` throw an uncaught PDOException and the script crashes before the final OK/FAIL summary and exit code are printed. Guard the admin/settings and idempotency checks behind a schema-ok condition (or catch PDOException) so a regression yields a clean FAIL result instead of a fatal.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| exit(1); | ||
| } | ||
|
|
||
| $root->exec('DROP DATABASE IF EXISTS ' . BOOTSTRAP_TEST_DB); |
There was a problem hiding this comment.
P1: When a developer already has a database named riskops_bootstrap_test, this test irreversibly deletes it before running. Generate a unique scratch database per run or refuse to proceed when the fixed name exists.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tools/fresh_bootstrap_test.php, line 104:
<comment>When a developer already has a database named `riskops_bootstrap_test`, this test irreversibly deletes it before running. Generate a unique scratch database per run or refuse to proceed when the fixed name exists.</comment>
<file context>
@@ -0,0 +1,186 @@
+ exit(1);
+}
+
+$root->exec('DROP DATABASE IF EXISTS ' . BOOTSTRAP_TEST_DB);
+$root->exec('CREATE DATABASE ' . BOOTSTRAP_TEST_DB
+ . ' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
</file context>
| if (is_array($u)) { | ||
| check('admin rol/durum/parola-degisimi zorunlu', | ||
| $u['role'] === 'admin' && (int)$u['status'] === 1 && (int)$u['must_change_password'] === 1); | ||
| check('admin departmana bagli (IT)', $u['department_id'] !== null); |
There was a problem hiding this comment.
P2: This check labeled IT only verifies that department_id is non-null, so a seed regression linking the admin to Finance or another department still passes. Assert the joined department code is IT.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tools/fresh_bootstrap_test.php, line 141:
<comment>This check labeled IT only verifies that `department_id` is non-null, so a seed regression linking the admin to Finance or another department still passes. Assert the joined department code is `IT`.</comment>
<file context>
@@ -0,0 +1,186 @@
+ if (is_array($u)) {
+ check('admin rol/durum/parola-degisimi zorunlu',
+ $u['role'] === 'admin' && (int)$u['status'] === 1 && (int)$u['must_change_password'] === 1);
+ check('admin departmana bagli (IT)', $u['department_id'] !== null);
+ check("password_verify('Admin123456')",
+ password_verify('Admin123456', (string)$u['password']));
</file context>
| check('admin departmana bagli (IT)', $u['department_id'] !== null); | |
| check('admin departmana bagli (IT)', | |
| (string)$pdo->query('SELECT code FROM departments WHERE id = ' . (int)$u['department_id'])->fetchColumn() === 'IT'); |
| } | ||
|
|
||
| const BOOTSTRAP_TEST_DB = 'riskops_bootstrap_test'; | ||
| const BOOTSTRAP_TEST_ROOT_PASS = 'riskops_local_root'; |
There was a problem hiding this comment.
P2: The documented Ubuntu setup authenticates MariaDB root through sudo mysql, but this test forces TCP root login with a committed password that setup never creates. Read the connection credentials and socket from the environment, or use the configured test database account.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tools/fresh_bootstrap_test.php, line 31:
<comment>The documented Ubuntu setup authenticates MariaDB root through `sudo mysql`, but this test forces TCP root login with a committed password that setup never creates. Read the connection credentials and socket from the environment, or use the configured test database account.</comment>
<file context>
@@ -0,0 +1,186 @@
+}
+
+const BOOTSTRAP_TEST_DB = 'riskops_bootstrap_test';
+const BOOTSTRAP_TEST_ROOT_PASS = 'riskops_local_root';
+
+$expectedTables = [
</file context>
| sort($tables2); | ||
| check('tablo sayisi degismedi (10)', $tables2 === $expectedTables, count($tables2) . ' tablo'); | ||
|
|
||
| $adminCount = (int)$pdo->query( |
There was a problem hiding this comment.
P3: When schema.sql fails (the exact regression this test guards against), later $pdo->query(...)->fetch() calls on users throw an uncaught PDOException and the script crashes before the final OK/FAIL summary and exit code are printed. Guard the admin/settings and idempotency checks behind a schema-ok condition (or catch PDOException) so a regression yields a clean FAIL result instead of a fatal.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tools/fresh_bootstrap_test.php, line 165:
<comment>When schema.sql fails (the exact regression this test guards against), later `$pdo->query(...)->fetch()` calls on `users` throw an uncaught PDOException and the script crashes before the final OK/FAIL summary and exit code are printed. Guard the admin/settings and idempotency checks behind a schema-ok condition (or catch PDOException) so a regression yields a clean FAIL result instead of a fatal.</comment>
<file context>
@@ -0,0 +1,186 @@
+sort($tables2);
+check('tablo sayisi degismedi (10)', $tables2 === $expectedTables, count($tables2) . ' tablo');
+
+$adminCount = (int)$pdo->query(
+ "SELECT COUNT(*) FROM users WHERE email = 'admin@riskops.local'"
+)->fetchColumn();
</file context>
|
Teşekkürler. Dört bulguyu da doğruladım, dördü de gerçekti. Özellikle schema.sql'deki eksik users tablosu ciddiydi: belgelenmiş Düzeltmeleri main'e bağımsız olarak uyguladım (2530ae1). PR'ları merge
cubic'in son admin korumasına yaptığı P1 eleştirisini de hesaba kattım: Eklenen regresyon testleri:
#7 açık kalıyor - orada karşılığı olmayan bir test var, kapsamı Tekrar teşekkürler, başka bulgunuz olursa memnuniyetle bakarım. |
Hata
README'nin belgelenmiş kurulum akışı (
sudo mysql riskops < database/schema.sql+seed.sql) boş bir veritabanında çalışamıyordu — iki yüzeyi olan tek kurulum deliği:CREATE TABLE usersyoktu:schema.sql'in ilk tablosu (departments)FOREIGN KEY (manager_id) REFERENCES users (id)içeriyor, bölüm 10 iseuserstablosunu yalnızca ALTER ediyordu (tablo "mevcut" varsayılıyordu). Boş kurulum ERROR 1005 (errno 150) ile ilk tabloda kırılıyordu.seed.sqlyalnızca mevcutadmin@riskops.localkaydını UPDATE ediyor; README'nin vaat ettiği ilk giriş hesabı (Admin123456, ilk girişte değişim zorunlu) oluşmuyordu — kurulum sonunda sisteme girilemiyordu.Çözüm
database/schema.sqlbölüm 0:CREATE TABLE IF NOT EXISTS users(temel kolonlar;roleENUM varsayılan'viewer'— en az yetki ilkesi). Bölüm 10'dakiIF NOT EXISTSALTER'lar aynen kaldı: mevcut kurulumlar için yükseltme yolu, bu yüzden dosya idempotent (üst üste çalıştırılabilir).database/seed.sql: belgelenmiş ilk adminINSERT IGNOREile eklenir (bcrypt hash,must_change_password=1); hemen altındaki mevcut UPDATE onu IT departmanına bağlar.Kanıt ve doğrulama
Proof-script gerçek
schema.sql+seed.sqldosyalarını boşaltılmış bir karalama veritabanında çalıştırdı:statement #4: ERROR 1005 ... Can't create table departments (errno: 150).password_verify('Admin123456')true.Dayanıklı regresyon testi
tools/fresh_bootstrap_test.php(yerel MariaDB ister; karalama veritabanını kendisi düşürür): 13 OK / 0 FAIL — boş kurulum ve dosyanın kendi idempotenti (ikinci uygulama: hatasız, admin/ayar kopyası yok).Mevcut kurulumlarda geriye dönük uyumluluk: düzeltilmiş
schema.sql+seed.sqlcanlı bir veritabanına yeniden uygulandı → temiz no-op.php tools/smoke_test.php: 58 OK / 1 FAIL (yalnızca/var/www/riskopsyerleşim yolu onaylaması — Windows checkout'ta karşılanamaz; işlevsel tüm kontroller geçiyor).Kapsam çiti
Bu PR yalnızca
database/schema.sql,database/seed.sqlvetools/fresh_bootstrap_test.phpdosyalarını değiştirir. Dal doğrudanmainüzerindendir; diğer açık PR'lara bağımlılığı yoktur.Summary by cubic
Fixes fresh database installation failing with ERROR 1005 because
schema.sqlnever created theuserstable, andseed.sqlnever inserted the documented initial admin account.CREATE TABLE IF NOT EXISTS userswith minimal columns; existing ALTERs remain idempotent for upgrades.admin@riskops.local/Admin123456) withINSERT IGNOREand forces password change.tools/fresh_bootstrap_test.phpto verify clean install and re-run idempotency.Written for commit 370c398. Summary will update on new commits.