-- ============================================================ -- WebGIS Database Schema -- Supports: Points (SPBU, Mosque, Poor Population), -- Lines (Roads), Polygons (Land Parcels) -- ============================================================ CREATE DATABASE IF NOT EXISTS webgis_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; USE webgis_db; -- ------------------------------------------------------------ -- TABLE: points -- Stores all point-type features (SPBU, Mosque, Poor Population) -- ------------------------------------------------------------ CREATE TABLE IF NOT EXISTS points ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, category ENUM('spbu','mosque','poor') NOT NULL COMMENT 'spbu=Gas Station, mosque=Mosque, poor=Poor Population', subtype VARCHAR(100) DEFAULT NULL COMMENT 'For SPBU: 24hours or not24hours', latitude DECIMAL(10,8) NOT NULL, longitude DECIMAL(11,8) NOT NULL, description TEXT DEFAULT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB; -- ------------------------------------------------------------ -- TABLE: roads -- Stores road polylines with GeoJSON geometry -- ------------------------------------------------------------ CREATE TABLE IF NOT EXISTS roads ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, road_type ENUM('national','provincial','district') NOT NULL, length_m DECIMAL(12,2) NOT NULL DEFAULT 0 COMMENT 'Length in meters, auto-calculated by frontend', geojson LONGTEXT NOT NULL COMMENT 'GeoJSON LineString geometry', description TEXT DEFAULT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB; -- ------------------------------------------------------------ -- TABLE: parcels -- Stores land parcel polygons with GeoJSON geometry -- ------------------------------------------------------------ CREATE TABLE IF NOT EXISTS parcels ( id INT AUTO_INCREMENT PRIMARY KEY, owner_name VARCHAR(255) NOT NULL, ownership_type ENUM('SHM','HGB','HGU','HP') NOT NULL, area_m2 DECIMAL(15,4) NOT NULL DEFAULT 0 COMMENT 'Area in square meters, auto-calculated by frontend', geojson LONGTEXT NOT NULL COMMENT 'GeoJSON Polygon geometry', description TEXT DEFAULT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB; -- ------------------------------------------------------------ -- Sample seed data (optional) -- ------------------------------------------------------------ INSERT INTO points (name, category, subtype, latitude, longitude, description) VALUES ('SPBU Jl. Sudirman', 'spbu', '24hours', -6.9175, 107.6191, 'SPBU di pusat kota'), ('SPBU Jl. Asia Afrika', 'spbu', 'not24hours', -6.9214, 107.6062, 'SPBU selatan kota'), ('Masjid Agung', 'mosque', NULL, -6.9200, 107.6100, 'Masjid Agung Bandung'), ('Masjid Al-Ikhlas', 'mosque', NULL, -6.9150, 107.6250, 'Masjid Kelurahan'), ('Lokasi Kemiskinan A', 'poor', NULL, -6.9300, 107.6050, 'Kawasan padat penduduk'), ('Lokasi Kemiskinan B', 'poor', NULL, -6.9350, 107.6150, 'RW 07 Kebon Jeruk');