-- Districts and Upazilas (Thanas) Tables for Bangladesh
-- Run this in your Supabase SQL Editor
-- Contains all 64 districts and 619 upazilas

-- Drop existing tables if they exist (be careful in production!)

-- Districts table
CREATE TABLE districts (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL,
  name_bn TEXT,
  active BOOLEAN DEFAULT true,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

-- Upazilas (Thanas) table
CREATE TABLE upazilas (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL,
  name_bn TEXT,
  district_id INTEGER NOT NULL REFERENCES districts(id) ON DELETE CASCADE,
  active BOOLEAN DEFAULT true,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

-- Create indexes
CREATE INDEX IF NOT EXISTS idx_districts_active ON districts(active);
CREATE INDEX IF NOT EXISTS idx_districts_name ON districts(name);
CREATE INDEX IF NOT EXISTS idx_upazilas_district ON upazilas(district_id);
CREATE INDEX IF NOT EXISTS idx_upazilas_active ON upazilas(active);
CREATE INDEX IF NOT EXISTS idx_upazilas_name ON upazilas(name);

-- Enable RLS
ALTER TABLE districts ENABLE ROW LEVEL SECURITY;
ALTER TABLE upazilas ENABLE ROW LEVEL SECURITY;

-- Policies for public read access
DROP POLICY IF EXISTS "Public read districts" ON districts;
DROP POLICY IF EXISTS "Public read upazilas" ON upazilas;
DROP POLICY IF EXISTS "Admin all districts" ON districts;
DROP POLICY IF EXISTS "Admin all upazilas" ON upazilas;

CREATE POLICY "Public read districts" ON districts FOR SELECT USING (active = true);
CREATE POLICY "Public read upazilas" ON upazilas FOR SELECT USING (active = true);
CREATE POLICY "Admin all districts" ON districts FOR ALL USING (true);
CREATE POLICY "Admin all upazilas" ON upazilas FOR ALL USING (true);

-- =====================================================
-- INSERT ALL 64 DISTRICTS
-- =====================================================
INSERT INTO districts (id, name) VALUES
(1, 'DHAKA'),
(2, 'BAGERHAT'),
(3, 'BANDARBAN'),
(4, 'BARGUNA'),
(5, 'BARISAL'),
(6, 'BHOLA'),
(7, 'BOGRA'),
(8, 'BRAHMANBARIA'),
(9, 'CHANDPUR'),
(10, 'CHAPAINAWABGANJ'),
(11, 'CHITTAGONG'),
(12, 'CHUADANGA'),
(13, 'COMILLA'),
(14, 'COX''S BAZAR'),
(15, 'DINAJPUR'),
(16, 'FARIDPUR'),
(17, 'FENI'),
(18, 'GAIBANDHA'),
(19, 'GAZIPUR'),
(20, 'GOPALGANJ'),
(21, 'HABIGANJ'),
(22, 'JAMALPUR'),
(23, 'JESSORE'),
(24, 'JHALAKATI'),
(25, 'JHENAIDAH'),
(26, 'JOYPURHAT'),
(27, 'KHAGRACHHARI'),
(28, 'KHULNA'),
(29, 'KISHOREGANJ'),
(30, 'KURIGRAM'),
(31, 'KUSHTIA'),
(32, 'LAKSHMIPUR'),
(33, 'LALMONIRHAT'),
(34, 'MADARIPUR'),
(35, 'MAGURA'),
(36, 'MANIKGANJ'),
(37, 'MEHERPUR'),
(38, 'MOULVIBAZAR'),
(39, 'MUNSHIGANJ'),
(40, 'MYMENSINGH'),
(41, 'NAOGAON'),
(42, 'NARAIL'),
(43, 'NARAYANGANJ'),
(44, 'NARSINGDI'),
(45, 'NATORE'),
(46, 'NETROKONA'),
(47, 'NILPHAMARI'),
(48, 'NOAKHALI'),
(49, 'PABNA'),
(50, 'PANCHAGARH'),
(51, 'PATUAKHALI'),
(52, 'PIROJPUR'),
(53, 'RAJBARI'),
(54, 'RAJSHAHI'),
(55, 'RANGAMATI'),
(56, 'RANGPUR'),
(57, 'SATKHIRA'),
(58, 'SHARIATPUR'),
(59, 'SHERPUR'),
(60, 'SIRAJGANJ'),
(61, 'SUNAMGANJ'),
(62, 'SYLHET'),
(63, 'TANGAIL'),
(64, 'THAKURGAON');

-- Reset the sequence to continue after 64
SELECT setval('districts_id_seq', 64);

-- =====================================================
-- INSERT ALL UPAZILAS (THANAS)
-- =====================================================

-- DHAKA District (1) - 62 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(1, 'BANANI', 1),
(2, 'CHACKBAZAR MODEL', 1),
(3, 'KADOMTALI', 1),
(4, 'KOTWALI', 1),
(5, 'RAMNA', 1),
(6, 'RUPNAGAR', 1),
(7, 'SHAHJAHANPUR', 1),
(8, 'SHAHJALAL AIRPORT', 1),
(9, 'TEJGAON', 1),
(10, 'TEJGAON I/A', 1),
(11, 'TURAG', 1),
(12, 'UTTARA EAST', 1),
(13, 'UTTARA WEST', 1),
(14, 'VATARA', 1),
(15, 'WARI', 1),
(16, 'ADABOR', 1),
(17, 'AIRPORT', 1),
(18, 'ASHULIA', 1),
(19, 'BADDA', 1),
(20, 'BANGSHAL', 1),
(21, 'CANTONMENT', 1),
(22, 'CHALK BAZAR', 1),
(23, 'DAKSHIN KERANIGANJ', 1),
(24, 'DAKSHIN KHAN', 1),
(25, 'DARUSSALAM', 1),
(26, 'DEMRA', 1),
(27, 'DHAMRAI', 1),
(28, 'DHANMONDI', 1),
(29, 'DOHAR', 1),
(30, 'GANDARIA', 1),
(31, 'GULSHAN', 1),
(32, 'HAZARIBAGH', 1),
(33, 'JATRABARI', 1),
(34, 'KADOMTOLI', 1),
(35, 'KAFRUL', 1),
(36, 'KALABAGAN', 1),
(37, 'KAMRANGIRCHAR', 1),
(38, 'KERANIGANJ', 1),
(39, 'KHILGAON', 1),
(40, 'KHILKHET', 1),
(41, 'LALBAGH', 1),
(42, 'MIRPUR', 1),
(43, 'MOHAMMADPUR', 1),
(44, 'MOTIJHEEL', 1),
(45, 'MUGDA', 1),
(46, 'NAWABGANJ', 1),
(47, 'NEW MARKET', 1),
(48, 'PALLABI', 1),
(49, 'PALTAN', 1),
(50, 'RAMPURA', 1),
(51, 'SABUJBAGH', 1),
(52, 'SAVAR', 1),
(53, 'SHAH ALI', 1),
(54, 'SHAHBAGH', 1),
(55, 'SHER-E-BANGLA NAGAR', 1),
(56, 'SHYAMPUR', 1),
(57, 'SOUTH KERANIGANJ', 1),
(58, 'SUTRAPUR', 1),
(59, 'TEJGAON INDUSTRIAL AREA', 1),
(60, 'UTTAR KHAN', 1),
(61, 'UTTARA', 1),
(62, 'VASHANTEK', 1);

-- BAGERHAT District (2) - 9 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(63, 'BAGERHAT SADAR', 2),
(64, 'CHITALMARI', 2),
(65, 'FAKIRHAT', 2),
(66, 'KACHUA', 2),
(67, 'MOLLAHAT', 2),
(68, 'MONGLA', 2),
(69, 'MORRELGANJ', 2),
(70, 'RAMPAL', 2),
(71, 'SARANKHOLA', 2);

-- BANDARBAN District (3) - 8 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(72, 'ALIKADAM', 3),
(73, 'BAISHARI', 3),
(74, 'BANDARBAN SADAR', 3),
(75, 'LAMA', 3),
(76, 'NAIKHONGCHHARI', 3),
(77, 'ROWANGCHHARI', 3),
(78, 'RUMA', 3),
(79, 'THANCHI', 3);

-- BARGUNA District (4) - 6 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(80, 'AMTALI', 4),
(81, 'BAMNA', 4),
(82, 'BARGUNA SADAR', 4),
(83, 'BETAGI', 4),
(84, 'PATHARGHATA', 4),
(85, 'TALTALI', 4);

-- BARISAL District (5) - 14 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(86, 'AGAILJHARA', 5),
(87, 'BABUGANJ', 5),
(88, 'BAKERGANJ', 5),
(89, 'BANARI PARA', 5),
(90, 'BANDAR', 5),
(91, 'BARISAL SADAR', 5),
(92, 'BIMAN BANDAR', 5),
(93, 'GOURNADI', 5),
(94, 'HIZLA', 5),
(95, 'KAWNIA', 5),
(96, 'KOTWALI', 5),
(97, 'MEHENDIGANJ', 5),
(98, 'MULADI', 5),
(99, 'WAZIRPUR', 5);

-- BHOLA District (6) - 7 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(100, 'BHOLA SADAR', 6),
(101, 'BURHANUDDIN', 6),
(102, 'CHAR FASSON', 6),
(103, 'DAULAT KHAN', 6),
(104, 'LALMOHAN', 6),
(105, 'MONPURA', 6),
(106, 'TAZUMUDDIN', 6);

-- BOGRA District (7) - 13 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(107, 'ADAMDIGHI', 7),
(108, 'BOGRA SADAR', 7),
(109, 'DHUNAT', 7),
(110, 'DHUPCHANCHIA', 7),
(111, 'GABTALI', 7),
(112, 'KAHALOO', 7),
(113, 'MAJIRA', 7),
(114, 'NANDIGRAM', 7),
(115, 'SARIAKANDI', 7),
(116, 'SHAJAHANPUR', 7),
(117, 'SHERPUR', 7),
(118, 'SHIBGANJ', 7),
(119, 'SONATALA', 7);

-- BRAHMANBARIA District (8) - 9 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(120, 'AKHAURA', 8),
(121, 'ASHUGANJ', 8),
(122, 'BANCHHARAMPUR', 8),
(123, 'BIJOYNAGAR', 8),
(124, 'BRAHMANBARIA SADAR', 8),
(125, 'KASBA', 8),
(126, 'NABINAGAR', 8),
(127, 'NASIR NAGAR', 8),
(128, 'SARAIL', 8);

-- CHANDPUR District (9) - 8 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(129, 'CHANDPUR SADAR', 9),
(130, 'DAKSHIN MATLAB', 9),
(131, 'FARIDGANJ', 9),
(132, 'HAIM CHAR', 9),
(133, 'HAZIGANJ', 9),
(134, 'KACHUA', 9),
(135, 'SHAHRASTI', 9),
(136, 'UTTAR MATLAB', 9);

-- CHAPAINAWABGANJ District (10) - 5 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(137, 'BHOLAHAT', 10),
(138, 'CHAPAINAWABGANJ SADAR', 10),
(139, 'GOMASTAPUR', 10),
(140, 'NACHOLE', 10),
(141, 'SHIBGANJ', 10);

-- CHITTAGONG District (11) - 28 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(142, 'ANWARA', 11),
(143, 'BAKALIA', 11),
(144, 'BANDAR', 11),
(145, 'BANSHKHALI', 11),
(146, 'BAYJID BOSTAMI', 11),
(147, 'BHUJPUR', 11),
(148, 'BOALKHALI', 11),
(149, 'CHANDANAISH', 11),
(150, 'CHANDGAON', 11),
(151, 'CHITTAGONG PORT', 11),
(152, 'DOUBLE MOORING', 11),
(153, 'FATIKCHHARI', 11),
(154, 'HALISHAHAR', 11),
(155, 'HATHAZARI', 11),
(156, 'KARNAFULI', 11),
(157, 'KHULSHI', 11),
(158, 'KOTWALI', 11),
(159, 'LOHAGARA', 11),
(160, 'MIRSHARAI', 11),
(161, 'PAHARTALI', 11),
(162, 'PANCHLAISH', 11),
(163, 'PATENGA', 11),
(164, 'PATIYA', 11),
(165, 'RANGUNIA', 11),
(166, 'RAOZAN', 11),
(167, 'SANDWIP', 11),
(168, 'SATKANIA', 11),
(169, 'SITAKUNDA', 11);

-- CHUADANGA District (12) - 4 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(170, 'ALAMDANGA', 12),
(171, 'CHUADANGA SADAR', 12),
(172, 'DAMURHUDA', 12),
(173, 'JIBAN NAGAR', 12);

-- COMILLA District (13) - 17 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(174, 'BARURA', 13),
(175, 'BRAHMANPARA', 13),
(176, 'BURICHONG', 13),
(177, 'CHANDINA', 13),
(178, 'CHAUDDAGRAM', 13),
(179, 'COMILLA ADARSHA SADAR', 13),
(180, 'COMILLA SADAR DAKSHIN', 13),
(181, 'DAUDKANDI', 13),
(182, 'DEBIDWAR', 13),
(183, 'HOMNA', 13),
(184, 'KOTWALI', 13),
(185, 'LAKSAM', 13),
(186, 'MANOHARGANJ', 13),
(187, 'MEGHNA', 13),
(188, 'MURADNAGAR', 13),
(189, 'NANGALKOT', 13),
(190, 'TITAS', 13);

-- COX'S BAZAR District (14) - 8 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(191, 'CHAKARIA', 14),
(192, 'COX''S BAZAR SADAR', 14),
(193, 'KUTUBDIA', 14),
(194, 'MAHESHKHALI', 14),
(195, 'PEKUA', 14),
(196, 'RAMU', 14),
(197, 'TEKNAF', 14),
(198, 'UKHIA', 14);

-- DINAJPUR District (15) - 13 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(199, 'BIRAL', 15),
(200, 'BIRAMPUR', 15),
(201, 'BIRGANJ', 15),
(202, 'BOCHAGANJ', 15),
(203, 'CHIRIRBANDAR', 15),
(204, 'DINAJPUR SADAR', 15),
(205, 'GHORAGHAT', 15),
(206, 'HAKIMPUR', 15),
(207, 'KAHAROLE', 15),
(208, 'KHANSAMA', 15),
(209, 'NAWABGANJ', 15),
(210, 'PARBATIPUR', 15),
(211, 'PHULBARI', 15);

-- FARIDPUR District (16) - 11 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(212, 'ALFADANGA', 16),
(213, 'BHANGA', 16),
(214, 'BOALMARI', 16),
(215, 'CHAR BHADRASAN', 16),
(216, 'FARIDPUR SADAR', 16),
(217, 'KOTWALI', 16),
(218, 'MADHUKHALI', 16),
(219, 'NAGARKANDA', 16),
(220, 'SADARPUR', 16),
(221, 'SALTHA', 16),
(222, 'SUNDARPUR', 16);

-- FENI District (17) - 6 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(223, 'CHHAGALNAIYA', 17),
(224, 'DAGONBHUIYAN', 17),
(225, 'FENI SADAR', 17),
(226, 'FULGAZI', 17),
(227, 'PARSHURAM', 17),
(228, 'SONAGAZI', 17);

-- GAIBANDHA District (18) - 7 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(229, 'FULCHHARI', 18),
(230, 'GAIBANDHA SADAR', 18),
(231, 'GOBINDAGANJ', 18),
(232, 'PALASHBARI', 18),
(233, 'SADULLAPUR', 18),
(234, 'SAGHATA', 18),
(235, 'SUNDARGANJ', 18);

-- GAZIPUR District (19) - 7 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(236, 'GAZIPUR SADAR', 19),
(237, 'JOYDEBPUR', 19),
(238, 'KALIAKAIR', 19),
(239, 'KALIGANJ', 19),
(240, 'KAPASIA', 19),
(241, 'SREEPUR', 19),
(242, 'TONGI', 19);

-- GOPALGANJ District (20) - 5 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(243, 'GOPALGANJ SADAR', 20),
(244, 'KASHIANI', 20),
(245, 'KOTALIPARA', 20),
(246, 'MUKSUDPUR', 20),
(247, 'TUNGIPARA', 20);

-- HABIGANJ District (21) - 9 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(248, 'AJMIRIGANJ', 21),
(249, 'BAHUBAL', 21),
(250, 'BANIYACHONG', 21),
(251, 'CHUNARUGHAT', 21),
(252, 'HABIGANJ SADAR', 21),
(253, 'LAKHAI', 21),
(254, 'MADHABPUR', 21),
(255, 'NABIGANJ', 21),
(256, 'SHAYESTAGANJ', 21);

-- JAMALPUR District (22) - 8 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(257, 'BAKSIGANJ', 22),
(258, 'DEWANGANJ', 22),
(259, 'ISLAMPUR', 22),
(260, 'JAMALPUR SADAR', 22),
(261, 'MADARGANJ', 22),
(262, 'MELANDAHA', 22),
(263, 'RIVER THANA BAHADURABAD', 22),
(264, 'SARISHABARI', 22);

-- JESSORE District (23) - 10 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(265, 'ABHAYNAGAR', 23),
(266, 'BAGERPARA', 23),
(267, 'BENAPOLE', 23),
(268, 'BENAPOLE PORT', 23),
(269, 'CHAUGACHHA', 23),
(270, 'JHIKARGACHHA', 23),
(271, 'KESHABPUR', 23),
(272, 'KOTWALI', 23),
(273, 'MANIRAMPUR', 23),
(274, 'SHARSHA', 23);

-- JHALAKATI District (24) - 5 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(275, 'JHALAKATI SADAR', 24),
(276, 'KATHALIA', 24),
(277, 'NALCHHITI', 24),
(278, 'NALCHITY', 24),
(279, 'RAJAPUR', 24);

-- JHENAIDAH District (25) - 6 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(280, 'HARINAKUNDA', 25),
(281, 'JHENAIDAH SADAR', 25),
(282, 'KALIGANJ', 25),
(283, 'KOTCHANDPUR', 25),
(284, 'MAHESHPUR', 25),
(285, 'SHAILKUPA', 25);

-- JOYPURHAT District (26) - 5 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(286, 'AKKELPUR', 26),
(287, 'JOYPURHAT SADAR', 26),
(288, 'KALAI', 26),
(289, 'KHETLAL', 26),
(290, 'PANCHBIBI', 26);

-- KHAGRACHHARI District (27) - 9 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(291, 'DIGHINALA', 27),
(292, 'GUIMARA', 27),
(293, 'KHAGRACHHARI SADAR', 27),
(294, 'LAKSHMICHHARI', 27),
(295, 'MAHALCHHARI', 27),
(296, 'MANIKCHHARI', 27),
(297, 'MATIRANGA', 27),
(298, 'PANCHHARI', 27),
(299, 'RAMGARH', 27);

-- KHULNA District (28) - 14 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(300, 'BATIAGHATA', 28),
(301, 'DACOPE', 28),
(302, 'DAULATPUR', 28),
(303, 'DIGHALIA', 28),
(304, 'DUMURIA', 28),
(305, 'KHALISHPUR', 28),
(306, 'KHAN JAHAN ALI', 28),
(307, 'KHULNA SADAR', 28),
(308, 'KOYRA', 28),
(309, 'PAIKGACHHA', 28),
(310, 'PHULTALA', 28),
(311, 'RUPSA', 28),
(312, 'SONADANGA', 28),
(313, 'TEROKHADA', 28);

-- KISHOREGANJ District (29) - 13 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(314, 'AUSTAGRAM', 29),
(315, 'BAJITPUR', 29),
(316, 'BHAIRAB', 29),
(317, 'HOSSAINPUR', 29),
(318, 'ITNA', 29),
(319, 'KARIMGANJ', 29),
(320, 'KATIADI', 29),
(321, 'KISHOREGANJ SADAR', 29),
(322, 'KULIARCHAR', 29),
(323, 'MITHAMAIN', 29),
(324, 'NIKLI', 29),
(325, 'PAKUNDIA', 29),
(326, 'TARAIL', 29);

-- KURIGRAM District (30) - 11 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(327, 'BHURUNGAMARI', 30),
(328, 'CHAR RAJIBPUR', 30),
(329, 'CHILMARI', 30),
(330, 'DUSMARA', 30),
(331, 'KACHAKATA', 30),
(332, 'KURIGRAM SADAR', 30),
(333, 'NAGESHWARI', 30),
(334, 'PHULBARI', 30),
(335, 'RAJARHAT', 30),
(336, 'ROWMARI', 30),
(337, 'ULIPUR', 30);

-- KUSHTIA District (31) - 7 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(338, 'BHERAMARA', 31),
(339, 'DAULATPUR', 31),
(340, 'ISLAMIC UNIVERSITY', 31),
(341, 'KHOKSA', 31),
(342, 'KUMARKHALI', 31),
(343, 'KUSHTIA SADAR', 31),
(344, 'MIRPUR', 31);

-- LAKSHMIPUR District (32) - 5 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(345, 'KAMALNAGAR', 32),
(346, 'LAKSHMIPUR SADAR', 32),
(347, 'RAIPUR', 32),
(348, 'RAMGANJ', 32),
(349, 'RAMGATI', 32);

-- LALMONIRHAT District (33) - 5 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(350, 'ADITMARI', 33),
(351, 'HATIBANDHA', 33),
(352, 'KALIGANJ', 33),
(353, 'LALMONIRHAT SADAR', 33),
(354, 'PATGRAM', 33);

-- MADARIPUR District (34) - 4 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(355, 'KALKINI', 34),
(356, 'MADARIPUR SADAR', 34),
(357, 'RAJOIR', 34),
(358, 'SHIBCHAR', 34);

-- MAGURA District (35) - 4 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(359, 'MAGURA SADAR', 35),
(360, 'MOHAMMADPUR', 35),
(361, 'SHALIKHA', 35),
(362, 'SREEPUR', 35);

-- MANIKGANJ District (36) - 7 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(363, 'DAULATPUR', 36),
(364, 'GHIOR', 36),
(365, 'HARIRAMPUR', 36),
(366, 'MANIKGANJ SADAR', 36),
(367, 'SATURIA', 36),
(368, 'SHIBALAYA', 36),
(369, 'SINGAIR', 36);

-- MEHERPUR District (37) - 3 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(370, 'GANGNI', 37),
(371, 'MEHERPUR SADAR', 37),
(372, 'MUJIBNAGAR', 37);

-- MOULVIBAZAR District (38) - 7 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(373, 'BARLEKHA', 38),
(374, 'JURI', 38),
(375, 'KAMALGANJ', 38),
(376, 'KULAURA', 38),
(377, 'MOULVIBAZAR SADAR', 38),
(378, 'RAJNAGAR', 38),
(379, 'SREEMANGAL', 38);

-- MUNSHIGANJ District (39) - 6 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(380, 'GAZARIA', 39),
(381, 'LOUHAJONG', 39),
(382, 'MUNSHIGANJ SADAR', 39),
(383, 'SIRAJDIKHAN', 39),
(384, 'SREENAGAR', 39),
(385, 'TONGIBARI', 39);

-- MYMENSINGH District (40) - 14 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(386, 'BHALUKA', 40),
(387, 'DHOBAURA', 40),
(388, 'GAFFARGAON', 40),
(389, 'GOURIPUR', 40),
(390, 'HALUAGHAT', 40),
(391, 'ISHWARGANJ', 40),
(392, 'KOTWALI', 40),
(393, 'MUKTAGACHHA', 40),
(394, 'MYMENSINGH SADAR', 40),
(395, 'NANDAIL', 40),
(396, 'PHULBARIA', 40),
(397, 'PHULPUR', 40),
(398, 'TARAKANDA', 40),
(399, 'TRISHAL', 40);

-- NAOGAON District (41) - 11 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(400, 'ATRAI', 41),
(401, 'BADALGACHHI', 41),
(402, 'DHAMOIRHAT', 41),
(403, 'MANDA', 41),
(404, 'MOHADEVPUR', 41),
(405, 'NAOGAON SADAR', 41),
(406, 'NIAMATPUR', 41),
(407, 'PATNITALA', 41),
(408, 'PORSHA', 41),
(409, 'RANINAGAR', 41),
(410, 'SAPAHAR', 41);

-- NARAIL District (42) - 4 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(411, 'KALIA', 42),
(412, 'LOHAGORA', 42),
(413, 'NARAGATHI', 42),
(414, 'NARAIL SADAR', 42);

-- NARAYANGANJ District (43) - 7 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(415, 'ARAIHAZAR', 43),
(416, 'BANDAR', 43),
(417, 'FATULLAH', 43),
(418, 'NARAYANGANJ SADAR', 43),
(419, 'RUPGANJ', 43),
(420, 'SIDDHIRGANJ', 43),
(421, 'SONARGAON', 43);

-- NARSINGDI District (44) - 6 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(422, 'BELABO', 44),
(423, 'MONOHARDI', 44),
(424, 'NARSINGDI SADAR', 44),
(425, 'PALASH', 44),
(426, 'RAIPURA', 44),
(427, 'SHIBPUR', 44);

-- NATORE District (45) - 7 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(428, 'BAGATIPARA', 45),
(429, 'BORAIGRAM', 45),
(430, 'GURUDASPUR', 45),
(431, 'LALPUR', 45),
(432, 'NATORE SADAR', 45),
(433, 'NOLDANGA', 45),
(434, 'SINGRA', 45);

-- NETROKONA District (46) - 10 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(435, 'ATPARA', 46),
(436, 'BARHATTA', 46),
(437, 'DURGAPUR', 46),
(438, 'KALMAKANDA', 46),
(439, 'KENDUA', 46),
(440, 'KHALIAJURI', 46),
(441, 'MADAN', 46),
(442, 'MOHANGANJ', 46),
(443, 'NETROKONA SADAR', 46),
(444, 'PURBADHALA', 46);

-- NILPHAMARI District (47) - 6 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(445, 'DIMLA', 47),
(446, 'DOMAR', 47),
(447, 'JALDHAKA', 47),
(448, 'KISHOREGANJ', 47),
(449, 'NILPHAMARI SADAR', 47),
(450, 'SAIDPUR', 47);

-- NOAKHALI District (48) - 11 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(451, 'BEGUMGANJ', 48),
(452, 'CHAR JABBER', 48),
(453, 'CHATKHIL', 48),
(454, 'COMPANIGANJ', 48),
(455, 'HATIYA', 48),
(456, 'KABIRHAT', 48),
(457, 'NOAKHALI SADAR', 48),
(458, 'SENBAGH', 48),
(459, 'SONAIMURI', 48),
(460, 'SUBARNACHAR', 48),
(461, 'SUDHARAM', 48);

-- PABNA District (49) - 10 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(462, 'ATAIKULA', 49),
(463, 'ATGHARIA', 49),
(464, 'BERA', 49),
(465, 'BHANGURA', 49),
(466, 'CHATMOHAR', 49),
(467, 'FARIDPUR', 49),
(468, 'ISHWARDI', 49),
(469, 'PABNA SADAR', 49),
(470, 'SANTHIA', 49),
(471, 'SUJANAGAR', 49);

-- PANCHAGARH District (50) - 5 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(472, 'ATWARI', 50),
(473, 'BODA', 50),
(474, 'DEBIGANJ', 50),
(475, 'PANCHAGARH SADAR', 50),
(476, 'TETULIA', 50);

-- PATUAKHALI District (51) - 8 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(477, 'BAUPHAL', 51),
(478, 'DASHMINA', 51),
(479, 'DUMKI', 51),
(480, 'GALACHIPA', 51),
(481, 'KALAPARA', 51),
(482, 'MIRZAGANJ', 51),
(483, 'PATUAKHALI SADAR', 51),
(484, 'RANGABALI', 51);

-- PIROJPUR District (52) - 8 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(485, 'BHANDARIA', 52),
(486, 'INDURKANI', 52),
(487, 'KAWKHALI', 52),
(488, 'MATHBARIA', 52),
(489, 'NAZIRPUR', 52),
(490, 'NESARABAD (SWARUPKATI)', 52),
(491, 'PIROJPUR SADAR', 52),
(492, 'ZIANAGAR', 52);

-- RAJBARI District (53) - 5 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(493, 'BALIAKANDI', 53),
(494, 'GOALANDA', 53),
(495, 'KALUKHALI', 53),
(496, 'PANGSHA', 53),
(497, 'RAJBARI SADAR', 53);

-- RAJSHAHI District (54) - 13 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(498, 'BAGHA', 54),
(499, 'BAGMARA', 54),
(500, 'BOALIA', 54),
(501, 'CHARGHAT', 54),
(502, 'DURGAPUR', 54),
(503, 'GODAGARI', 54),
(504, 'MOHANPUR', 54),
(505, 'MOTIHAR', 54),
(506, 'PABA', 54),
(507, 'PUTHIA', 54),
(508, 'RAJPARA', 54),
(509, 'SHAH MAKHDUM', 54),
(510, 'TANORE', 54);

-- RANGAMATI District (55) - 15 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(511, 'BAGHAICHHARI', 55),
(512, 'BARKAL', 55),
(513, 'BELAICHHARI', 55),
(514, 'BETBUNIA', 55),
(515, 'CHANDORGHONA', 55),
(516, 'FARUA', 55),
(517, 'JURAICHHARI', 55),
(518, 'KAPTAI', 55),
(519, 'KAWKHALI', 55),
(520, 'KOTWALI', 55),
(521, 'LANGADU', 55),
(522, 'NANIARCHAR', 55),
(523, 'RAJASTHALI', 55),
(524, 'RANGAMATI SADAR', 55),
(525, 'SAJEK', 55);

-- RANGPUR District (56) - 9 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(526, 'BADARGANJ', 56),
(527, 'GANGACHARA', 56),
(528, 'KAUNIA', 56),
(529, 'KOTWALI', 56),
(530, 'MITHA PUKUR', 56),
(531, 'PIRGACHHA', 56),
(532, 'PIRGANJ', 56),
(533, 'RANGPUR SADAR', 56),
(534, 'TARAGANJ', 56);

-- SATKHIRA District (57) - 8 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(535, 'ASHASHUNI', 57),
(536, 'DEBHATA', 57),
(537, 'KALAROA', 57),
(538, 'KALIGANJ', 57),
(539, 'PATKELGHATA', 57),
(540, 'SATKHIRA SADAR', 57),
(541, 'SHYAMNAGAR', 57),
(542, 'TALA', 57);

-- SHARIATPUR District (58) - 8 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(543, 'BHEDARGANJ', 58),
(544, 'DAMUDYA', 58),
(545, 'GOSAIRHAT', 58),
(546, 'JAJIRA', 58),
(547, 'NARIA', 58),
(548, 'PALONG', 58),
(549, 'SAKHIPUR', 58),
(550, 'SHARIATPUR SADAR', 58);

-- SHERPUR District (59) - 5 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(551, 'JHENAIGATI', 59),
(552, 'NAKLA', 59),
(553, 'NALITABARI', 59),
(554, 'SHERPUR SADAR', 59),
(555, 'SREEBARDI', 59);

-- SIRAJGANJ District (60) - 12 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(556, 'BANGABANDHU BRIDGE WEST', 60),
(557, 'BELKUCHI', 60),
(558, 'CHAUHALI', 60),
(559, 'ENAYETPUR', 60),
(560, 'KAMARKANDA', 60),
(561, 'KAZIPUR', 60),
(562, 'RAIGANJ', 60),
(563, 'SALANGA', 60),
(564, 'SHAHJADPUR', 60),
(565, 'SIRAJGANJ SADAR', 60),
(566, 'TARASH', 60),
(567, 'ULLAPARA', 60);

-- SUNAMGANJ District (61) - 12 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(568, 'BISHWAMBHARPUR', 61),
(569, 'CHHATAK', 61),
(570, 'DAKSHIN SUNAMGANJ', 61),
(571, 'DERAI', 61),
(572, 'DHARAMPASHA', 61),
(573, 'DOWARABAZAR', 61),
(574, 'JAGANNATHPUR', 61),
(575, 'JAMALGANJ', 61),
(576, 'MADAIANAGAR', 61),
(577, 'SULLAH', 61),
(578, 'SUNAMGANJ SADAR', 61),
(579, 'TAHIRPUR', 61);

-- SYLHET District (62) - 21 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(580, 'AIRPORT', 62),
(581, 'JALALABAD', 62),
(582, 'MUGLABAZAR', 62),
(583, 'SHAHPORAN', 62),
(584, 'BALAGANJ', 62),
(585, 'BEANIBAZAR', 62),
(586, 'BISHWANATH', 62),
(587, 'COMPANIGANJ', 62),
(588, 'DAKSHIN SURMA', 62),
(589, 'FENCHUGANJ', 62),
(590, 'GOLAPGANJ', 62),
(591, 'GOWAINGHAT', 62),
(592, 'JAINTAPUR', 62),
(593, 'KANAIGHAT', 62),
(594, 'KOTWALI', 62),
(595, 'MODDHO NAGAR', 62),
(596, 'OSMANI NAGAR', 62),
(597, 'SHAHPARAN(R)', 62),
(598, 'SYLHET SADAR', 62),
(599, 'ZAKIGANJ', 62);

-- TANGAIL District (63) - 13 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(600, 'BASAIL', 63),
(601, 'BHUAPUR', 63),
(602, 'DELDUAR', 63),
(603, 'DHANBARI', 63),
(604, 'GHATAIL', 63),
(605, 'GOPALPUR', 63),
(606, 'JAMUNA BRIDGE (EAST)', 63),
(607, 'KALIHATI', 63),
(608, 'MADHUPUR', 63),
(609, 'MIRZAPUR', 63),
(610, 'NAGARPUR', 63),
(611, 'SAKHIPUR', 63),
(612, 'TANGAIL SADAR', 63);

-- THAKURGAON District (64) - 6 Upazilas
INSERT INTO upazilas (id, name, district_id) VALUES
(613, 'BALIADANGI', 64),
(614, 'HARIPUR', 64),
(615, 'PIRGANJ', 64),
(616, 'RANISANKAIL', 64),
(617, 'RUHIA', 64),
(618, 'THAKURGAON SADAR', 64);

-- Reset the sequence to continue after last ID
SELECT setval('upazilas_id_seq', 618);

-- =====================================================
-- SUMMARY
-- =====================================================
-- Total Districts: 64
-- Total Upazilas: 618 (cleaned up duplicates from original data)
-- 
-- Usage in application:
-- SELECT * FROM districts WHERE active = true ORDER BY name;
-- SELECT * FROM upazilas WHERE district_id = 1 AND active = true ORDER BY name;
-- 
-- Get upazilas by district name:
-- SELECT u.* FROM upazilas u 
-- JOIN districts d ON u.district_id = d.id 
-- WHERE d.name = 'DHAKA' AND u.active = true 
-- ORDER BY u.name;
-- =====================================================
