| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #!/bin/bash
- # Diretório do projeto (um nível acima deste script)
- PROJECT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
- # Caminho absoluto do arquivo do banco de dados dentro do projeto
- DB_FILE="$PROJECT_DIR/test.db"
- # Executa comandos SQL no SQLite
- sqlite3 "$DB_FILE" <<EOF
- -- Cria tabela 'user' se não existir, com coluna 'user_password'
- CREATE TABLE IF NOT EXISTS user (
- user_id INTEGER PRIMARY KEY AUTOINCREMENT,
- user_name TEXT NOT NULL,
- user_flag TEXT NOT NULL,
- user_password TEXT NOT NULL -- Nova coluna para senha hasheada
- );
- -- Cria tabela 'api_key' se não existir
- CREATE TABLE IF NOT EXISTS api_key (
- api_key_id INTEGER PRIMARY KEY AUTOINCREMENT,
- user_id INTEGER NOT NULL,
- api_key_user TEXT NOT NULL,
- api_key_secret TEXT NOT NULL,
- FOREIGN KEY (user_id) REFERENCES user(user_id)
- );
- -- Cria tabela 'teste' se não existir
- CREATE TABLE IF NOT EXISTS teste (
- teste_id INTEGER PRIMARY KEY AUTOINCREMENT,
- field1 TEXT NOT NULL,
- field2 TEXT NULL,
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP
- );
- -- Cria tabela 'cpr_preregistration' se não existir
- CREATE TABLE IF NOT EXISTS cpr_preregistration (
- cpr_id INTEGER PRIMARY KEY AUTOINCREMENT,
- name TEXT NOT NULL,
- contact_number TEXT NOT NULL,
- email TEXT NOT NULL,
- product_type TEXT NOT NULL,
- internal_control_number TEXT NOT NULL,
- product_quantity INTEGER NOT NULL,
- property_name TEXT NOT NULL,
- property_location TEXT NOT NULL,
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP
- );
- -- Insere usuário de exemplo ('admin') com senha hasheada se não existir
- -- Hash de 'pass' (gere com user_password_hash em PHP e substitua)
- INSERT OR IGNORE INTO user (user_name, user_flag, user_password) VALUES ('admin', 'a', '$2y$10$K.0XhB3kXjZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZfZ');
- -- Insere chave API para o usuário 'admin' se não existir
- INSERT OR IGNORE INTO api_key (user_id, api_key_user, api_key_secret)
- SELECT user_id, 'myapikey', 'myapisecret' FROM user WHERE user_name = 'admin';
- -- Opcional: Insere mais um usuário de teste com senha hasheada
- -- Hash de 'testpass' (substitua pelo real)
- INSERT OR IGNORE INTO user (user_name, user_flag, user_password) VALUES ('testuser', 'a', '$2y$10$AnotherHashHereForTestPass');
- INSERT OR IGNORE INTO api_key (user_id, api_key_user, api_key_secret)
- SELECT user_id, 'testapikey', 'testapisecret' FROM user WHERE user_name = 'testuser';
- -- Exibe os dados inseridos para verificação (sem mostrar hash real por segurança)
- SELECT user_id, user_name, user_flag FROM user;
- SELECT * FROM api_key;
- SELECT * FROM teste;
- SELECT * FROM cpr_preregistration;
- EOF
- echo "Banco de dados '$DB_FILE' criado e populado com sucesso! Senhas estão hasheadas."
|