"""seed initial data Revision ID: 20241204_0000 Revises: initial_schema Create Date: 2024-12-04 00:00:00.000000 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa from datetime import datetime, timezone from app.core.security import get_password_hash # revision identifiers, used by Alembic. revision: str = '20241204_0000' down_revision: Union[str, None] = 'initial_schema' branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # Seed roles op.execute(""" INSERT INTO roles (id, name, description, is_active) VALUES ('0196a031-a540-78ca-a0d2-ccfb6fb6823c', 'data_viewer', 'Contoh deskripsi', true), ('01968027-048b-7166-9b71-412e178f65ee', 'administrator', 'Contoh deskripsi', true), ('0196802b-b5e8-740b-9f0c-b7e423aff947', 'data_validator', 'Contoh deskripsi', true), ('01969f62-aae2-7b59-9e23-da29223f70e1', 'data_manager', 'Contoh deskripsi', true) ON CONFLICT (id) DO NOTHING; """) # Seed regional op.execute(""" INSERT INTO regionals (id, code, name, description, thumbnail, is_active, created_at, updated_at) VALUES ( '01968b53-a910-7a67-bd10-975b8923b92e', '35.00', 'Jawa Timur', 'Provinsi Jawa Timur', NULL, true, '2025-04-29 13:04:51.693000+00', '2025-04-29 13:04:51.693000+00' ) ON CONFLICT (id) DO NOTHING; """) # Seed organization op.execute(""" INSERT INTO organizations (id, name, description, thumbnail, address, phone_number, email, website, is_active, is_deleted, created_at, modified_at) VALUES ( '01968b54-0000-7a67-bd10-975b8923b92e', 'Kominfo', 'Kementerian Komunikasi dan Informatika', NULL, NULL, NULL, 'info@kominfo.go.id', 'https://www.kominfo.go.id', true, false, NOW(), NOW() ), ( '01968b54-0000-7a67-bd10-975b8923b93e', 'Lab AI', 'Laboratorium Applied Informatics Polinema', NULL, Politeknik Negeri Malang, '0341404424', 'labai@gmail.com', 'http://labai.polinema.ac.id/homepage/', true, false, NOW(), NOW() ) ON CONFLICT (id) DO NOTHING; """) # Seed user admin # Password: admin123 (hashed with bcrypt using get_password_hash) hashed_password = get_password_hash("admin123") op.execute(f""" INSERT INTO users ( id, name, email, profile_picture, username, password, position, role_id, employee_id, organization_id, is_active, is_deleted, created_at, modified_at ) VALUES ( '01968b55-0000-7a67-bd10-975b8923b92e', 'Administrator Kominfo', 'admin@kominfo.go.id', NULL, 'admin', '{hashed_password}', 'System Administrator', '01968027-048b-7166-9b71-412e178f65ee', NULL, '01968b54-0000-7a67-bd10-975b8923b92e', true, false, NOW(), NOW() ) ON CONFLICT (username) DO NOTHING; """) op.execute(""" INSERT INTO public.categories( id, name, description, thumbnail, count_mapset, is_active, "order" ) VALUES ('019a0997-5b42-7c34-9ab8-35b4765ecb39', 'Batas Wilayah', 'Batas Wilayah', NULL, 0, true, 0), ('0196c80b-e680-7dca-9b90-b5ebe65de70d', 'Kependudukan', 'Kependudukan', NULL, 0, true, 0), ('0196c80c-855f-77f9-abd0-0c8a30b8c2f5', 'Lingkungan Hidup', 'Lingkungan Hidup', NULL, 0, true, 0), ('0196c80c-f805-76a8-82c7-af50b794871b', 'Pemerintah Desa', 'Pemerintah Desa', NULL, 0, true, 0), ('0196c80d-228d-7e1e-9116-78ba912b812c', 'Pendidikan', 'Pendidikan', NULL, 0, true, 0), ('0196c80d-3f05-7750-ab2a-f58655fef6ea', 'Sosial', 'Sosial', NULL, 0, true, 0), ('019936a6-4a5b-719f-8d88-d2df0af5aa20', 'Pendidikan SD', 'Pendidikan SD', NULL, 0, true, 0), ('0196c80c-c4fc-7ea6-afc0-3672a1b44b5b', 'Pariwisata Kebudayaan', 'Pariwisata Kebudayaan', NULL, 0, true, 0), ('0196c80c-61d8-7616-9abc-550a89283a57', 'Kesehatan', 'Kesehatan', NULL, 0, true, 0), ('0196c809-a0b0-79fb-b597-422d716fdce8', 'Ekonomi', 'Ekonomi', NULL, 0, true, 0), ('0196c80b-bb09-7424-9cd5-e3ec4946c7af', 'Kemiskinan', 'Kemiskinan', NULL, 0, true, 0), ('0196c80b-8710-7577-bc28-3ce66a02f56f', 'Infrastruktur', 'Infrastruktur', NULL, 0, true, 0); ON CONFLICT (id) DO NOTHING; """) op.execute(""" INSERT INTO public.classifications (id, name, is_open, is_limited, is_secret) VALUES ('01968b4b-d3f9-76c9-888c-ee887ac31ce4', 'terbuka', true, false, false), ('01968b4c-0c2b-7fea-a4cf-0f332fcb0025', 'terbatas', true, true, false), ('01968b4c-2e16-7c96-a982-6fd1e2abd378', 'rahasia', true, false, true); """) op.execute(""" INSERT INTO public.map_projection_systems (id, name) VALUES ('0196c746-d1ba-7f1c-9706-5df738679cc7', 'WGS 84'); """) def downgrade() -> None: # Delete in reverse order due to foreign key constraints op.execute("DELETE FROM users WHERE username = 'admin';") op.execute("DELETE FROM organizations WHERE name = 'Kominfo';") op.execute("DELETE FROM regionals WHERE code = '35.00';") op.execute("DELETE FROM roles WHERE name IN ('data_viewer', 'administrator', 'data_validator', 'data_manager');")