-- Setup database untuk CombineWebgis.
-- Import file ini lewat phpMyAdmin atau MySQL CLI setelah MySQL XAMPP berjalan normal.
-- Catatan: tabel project akan dibuat ulang agar schema bersih dan cocok dengan kode PHP.

CREATE DATABASE IF NOT EXISTS db_spbu
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;

USE db_spbu;

DROP TABLE IF EXISTS spbu;

CREATE TABLE spbu (
  id INT(11) NOT NULL AUTO_INCREMENT,
  nama_spbu VARCHAR(100) NOT NULL,
  no_wa VARCHAR(20) NOT NULL,
  status ENUM('yes','no') NOT NULL DEFAULT 'no',
  latitude DOUBLE NOT NULL,
  longitude DOUBLE NOT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO spbu (nama_spbu, no_wa, status, latitude, longitude) VALUES
('SPBU Gajah Mada', '08115700101', 'yes', -0.0227, 109.3294),
('SPBU Ahmad Yani', '08115700102', 'no', -0.0350, 109.3350),
('SPBU Tanjungpura', '08115700103', 'yes', -0.0180, 109.3410);

CREATE DATABASE IF NOT EXISTS webgis_db
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;

USE webgis_db;

DROP TABLE IF EXISTS tb_jalan_rusak;
DROP TABLE IF EXISTS tb_parsil;
DROP TABLE IF EXISTS tb_jalan;

CREATE TABLE tb_jalan (
  id INT(11) NOT NULL AUTO_INCREMENT,
  nama_jalan VARCHAR(200) NOT NULL,
  status_jalan ENUM('Nasional','Provinsi','Kabupaten') NOT NULL DEFAULT 'Kabupaten',
  panjang_meter DECIMAL(15,2) NOT NULL DEFAULT 0,
  geojson LONGTEXT NOT NULL,
  keterangan TEXT,
  foto VARCHAR(255) NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE tb_parsil (
  id INT(11) NOT NULL AUTO_INCREMENT,
  nama_pemilik VARCHAR(200) NOT NULL,
  no_sertifikat VARCHAR(100) NOT NULL,
  status_kepemilikan ENUM('SHM','HGB','HGU','HP') NOT NULL DEFAULT 'SHM',
  luas_m2 DECIMAL(20,4) NOT NULL DEFAULT 0,
  geojson LONGTEXT NOT NULL,
  alamat TEXT,
  foto VARCHAR(255) NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE tb_jalan_rusak (
  id INT(11) NOT NULL AUTO_INCREMENT,
  lokasi VARCHAR(200) NOT NULL,
  tingkat ENUM('Ringan','Sedang','Berat') NOT NULL DEFAULT 'Sedang',
  jenis VARCHAR(100) NOT NULL DEFAULT '',
  geojson LONGTEXT NOT NULL,
  keterangan TEXT,
  foto VARCHAR(255) NULL,
  tanggal_lapor DATE NOT NULL DEFAULT (CURRENT_DATE),
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO tb_jalan (nama_jalan, status_jalan, panjang_meter, geojson, keterangan) VALUES
('Jl. Ahmad Yani','Nasional',1240.50,'{"type":"Feature","geometry":{"type":"LineString","coordinates":[[109.3272,-0.0207],[109.3290,-0.0215],[109.3310,-0.0225],[109.3335,-0.0238]]},"properties":{}}','Jalan Nasional utama kota Pontianak'),
('Jl. Gajah Mada','Provinsi',870.00,'{"type":"Feature","geometry":{"type":"LineString","coordinates":[[109.3250,-0.0260],[109.3265,-0.0270],[109.3280,-0.0285]]},"properties":{}}','Jalan Provinsi pusat kota'),
('Jl. Pahlawan','Kabupaten',540.75,'{"type":"Feature","geometry":{"type":"LineString","coordinates":[[109.3300,-0.0300],[109.3315,-0.0310],[109.3325,-0.0322]]},"properties":{}}','Jalan Kabupaten lingkungan');

INSERT INTO tb_parsil (nama_pemilik, no_sertifikat, status_kepemilikan, luas_m2, geojson, alamat) VALUES
('Budi Santoso','SHM-001/PTK/2023','SHM',4500.00,'{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[109.3280,-0.0240],[109.3295,-0.0240],[109.3295,-0.0255],[109.3280,-0.0255],[109.3280,-0.0240]]]},"properties":{}}','Jl. Ahmad Yani No. 10, Pontianak'),
('PT. Maju Jaya','HGB-005/PTK/2022','HGB',12000.00,'{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[109.3310,-0.0220],[109.3330,-0.0220],[109.3330,-0.0240],[109.3310,-0.0240],[109.3310,-0.0220]]]},"properties":{}}','Kawasan Industri Pontianak');

INSERT INTO tb_jalan_rusak (lokasi, tingkat, jenis, geojson, keterangan, tanggal_lapor) VALUES
('Depan SPBU Jl. Ahmad Yani','Berat','Berlubang','{"type":"Feature","geometry":{"type":"Point","coordinates":[109.3285,-0.0212]},"properties":{}}','Lubang besar diameter sekitar 50cm, berbahaya bagi pengendara','2024-10-15'),
('Pertigaan Jl. Gajah Mada','Sedang','Retak','{"type":"Feature","geometry":{"type":"Point","coordinates":[109.3260,-0.0268]},"properties":{}}','Retak memanjang sepanjang 3 meter','2024-11-02');
