78 lines
3.7 KiB
Python
78 lines
3.7 KiB
Python
# Mengimpor modul Any dari typing untuk type hint variabel
|
|
from typing import Any
|
|
# Mengimpor tipe-tipe data kolom dari SQLAlchemy: Column (kolom), Integer (angka), String (teks pendek), Text (teks panjang), DateTime (waktu), Boolean (benar/salah)
|
|
from sqlalchemy import Column, Integer, String, Text, DateTime, Boolean
|
|
# Mengimpor relationship dari sqlalchemy.orm untuk mendefinisikan relasi antar tabel (One-to-One atau One-to-Many)
|
|
from sqlalchemy.orm import relationship
|
|
# Mengimpor func untuk fungsi SQL bawaan seperti pengambilan timestamp waktu sekarang
|
|
from sqlalchemy.sql import func
|
|
# Mengimpor Base sebagai kelas induk deklaratif ORM
|
|
from app.models.base import Base
|
|
|
|
|
|
# Mendefinisikan model ORM untuk tabel data pokok Alumni
|
|
class Alumni(Base):
|
|
# Nama fisik tabel alumni di database MySQL
|
|
__tablename__ = "alumni"
|
|
|
|
# Kolom ID utama entitas alumni (Primary Key bertipe integer dan terindeks)
|
|
id: Any = Column(Integer, primary_key=True, index=True)
|
|
|
|
# Kolom NIM (Nomor Induk Mahasiswa) sebagai identitas unik alumni yang terindeks dan wajib diisi
|
|
nim: Any = Column(String(50), unique=True, index=True, nullable=False)
|
|
|
|
# Kolom nama lengkap alumni (maksimal 255 karakter, tidak boleh kosong)
|
|
nama: Any = Column(String(255), nullable=False)
|
|
|
|
# Kolom tahun kelulusan alumni (tipe integer, misal: 2021, 2022, 2023)
|
|
tahun_lulus: Any = Column(Integer, nullable=False)
|
|
|
|
# Kolom kode program studi asal alumni (contoh: '57401' untuk Teknik Informatika)
|
|
kode_prodi: Any = Column(String(10), nullable=False)
|
|
|
|
# Kolom status pekerjaan saat ini (misal: 'bekerja', 'wiraswasta', 'belum_kerja', 'studi_lanjut')
|
|
status_kerja: Any = Column(String(50), nullable=True, default=None)
|
|
|
|
# Kolom teks bebas untuk posisi/jabatan pekerjaan alumni dari data mentah kuesioner
|
|
pekerjaan: Any = Column(Text, nullable=True, default=None) # Kolom text bebas di tabel
|
|
|
|
# Kolom teks bebas untuk nama perusahaan/instansi tempat alumni bekerja
|
|
instansi: Any = Column(Text, nullable=True, default=None) # Kolom text bebas di tabel
|
|
|
|
# Kolom alamat email aktif alumni
|
|
email: Any = Column(String(255), nullable=True, default=None)
|
|
|
|
# Kolom nomor telepon / WhatsApp alumni
|
|
no_hp: Any = Column(String(50), nullable=True, default=None)
|
|
|
|
# ===== Definisi Relasi ORM ke Tabel Lain (Relationship) =====
|
|
# Relasi One-to-One (uselist=False) ke tabel detail pekerjaan (tabel 'pekerjaan')
|
|
pekerjaan_detail = relationship("Pekerjaan", back_populates="alumni", uselist=False)
|
|
|
|
# Relasi One-to-One (uselist=False) ke tabel kompetensi alumni (tabel 'kompetensi')
|
|
kompetensi = relationship("Kompetensi", back_populates="alumni", uselist=False)
|
|
|
|
# Relasi One-to-One (uselist=False) ke tabel jawaban kuesioner lengkap tracer study (tabel 'tracer_responses')
|
|
tracer_response = relationship("TracerResponse", back_populates="alumni", uselist=False)
|
|
|
|
# Relasi One-to-Many ke tabel hasil klastering KMeans (satu alumni bisa memiliki riwayat hasil klastering di beberapa versi model)
|
|
clustering_results = relationship("ClusteringResult", back_populates="alumni")
|
|
|
|
# Kolom waktu pencatatan data alumni pertama kali dibuat
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
# Kolom waktu pembaruan terakhir data alumni
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
|
|
# Mengimpor class model terkait dari file models.py agar SQLAlchemy dapat memetakan relasi antar tabel (relationship) tanpa circular import
|
|
from app.models.models import (
|
|
Pekerjaan,
|
|
Kompetensi,
|
|
TracerResponse,
|
|
ClusteringResult,
|
|
ModelEvaluation,
|
|
KeywordDictionary
|
|
)
|
|
|