setup 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. # Diretório do projeto (um nível acima deste script)
  3. PROJECT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
  4. # Caminho absoluto do arquivo do banco de dados dentro do projeto
  5. DB_FILE="$PROJECT_DIR/test.db"
  6. # Executa comandos SQL no SQLite
  7. sqlite3 "$DB_FILE" <<EOF
  8. -- Cria tabela 'user' se não existir, com coluna 'user_password'
  9. CREATE TABLE IF NOT EXISTS user (
  10. user_id INTEGER PRIMARY KEY AUTOINCREMENT,
  11. user_name TEXT NOT NULL,
  12. user_flag TEXT NOT NULL,
  13. user_password TEXT NOT NULL -- Nova coluna para senha hasheada
  14. );
  15. -- Cria tabela 'api_key' se não existir
  16. CREATE TABLE IF NOT EXISTS api_key (
  17. api_key_id INTEGER PRIMARY KEY AUTOINCREMENT,
  18. user_id INTEGER NOT NULL,
  19. api_key_user TEXT NOT NULL,
  20. api_key_secret TEXT NOT NULL,
  21. FOREIGN KEY (user_id) REFERENCES user(user_id)
  22. );
  23. -- Cria tabela 'teste' se não existir
  24. CREATE TABLE IF NOT EXISTS teste (
  25. teste_id INTEGER PRIMARY KEY AUTOINCREMENT,
  26. field1 TEXT NOT NULL,
  27. field2 TEXT NULL,
  28. created_at DATETIME DEFAULT CURRENT_TIMESTAMP
  29. );
  30. -- Cria tabela 'cpr_preregistration' se não existir
  31. CREATE TABLE IF NOT EXISTS cpr_preregistration (
  32. cpr_id INTEGER PRIMARY KEY AUTOINCREMENT,
  33. name TEXT NOT NULL,
  34. contact_number TEXT NOT NULL,
  35. email TEXT NOT NULL,
  36. product_type TEXT NOT NULL,
  37. internal_control_number TEXT NOT NULL,
  38. product_quantity INTEGER NOT NULL,
  39. property_name TEXT NOT NULL,
  40. property_location TEXT NOT NULL,
  41. created_at DATETIME DEFAULT CURRENT_TIMESTAMP
  42. );
  43. -- Insere usuário de exemplo ('admin') com senha hasheada se não existir
  44. -- Hash de 'pass' (gere com user_password_hash em PHP e substitua)
  45. INSERT OR IGNORE INTO user (user_name, user_flag, user_password) VALUES ('admin', 'a', '$2y$10$K.0XhB3kXjZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZ');
  46. -- Insere chave API para o usuário 'admin' se não existir
  47. INSERT OR IGNORE INTO api_key (user_id, api_key_user, api_key_secret)
  48. SELECT user_id, 'myapikey', 'myapisecret' FROM user WHERE user_name = 'admin';
  49. -- Opcional: Insere mais um usuário de teste com senha hasheada
  50. -- Hash de 'testpass' (substitua pelo real)
  51. INSERT OR IGNORE INTO user (user_name, user_flag, user_password) VALUES ('testuser', 'a', '$2y$10$AnotherHashHereForTestPass');
  52. INSERT OR IGNORE INTO api_key (user_id, api_key_user, api_key_secret)
  53. SELECT user_id, 'testapikey', 'testapisecret' FROM user WHERE user_name = 'testuser';
  54. -- Exibe os dados inseridos para verificação (sem mostrar hash real por segurança)
  55. SELECT user_id, user_name, user_flag FROM user;
  56. SELECT * FROM api_key;
  57. SELECT * FROM teste;
  58. SELECT * FROM cpr_preregistration;
  59. EOF
  60. echo "Banco de dados '$DB_FILE' criado e populado com sucesso! Senhas estão hasheadas."