CREATE DATABASE rfid_enterprise;
USE rfid_enterprise;

CREATE TABLE siswa (
id INT AUTO_INCREMENT PRIMARY KEY,
nisn VARCHAR(20) UNIQUE,
nama VARCHAR(100),
kelas VARCHAR(20),
kode_rfid VARCHAR(50) UNIQUE,
foto VARCHAR(255) NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE kegiatan (
id INT AUTO_INCREMENT PRIMARY KEY,
nama_kegiatan VARCHAR(100),
tanggal DATE,
status ENUM('aktif','nonaktif') DEFAULT 'nonaktif',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE presensi (
id INT AUTO_INCREMENT PRIMARY KEY,
siswa_id INT,
kegiatan_id INT,
waktu DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (siswa_id) REFERENCES siswa(id) ON DELETE CASCADE,
FOREIGN KEY (kegiatan_id) REFERENCES kegiatan(id) ON DELETE CASCADE
);
