Spaces:
Running
Running
File size: 1,300 Bytes
50efdc6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | """
src/db/setup_sqlite.py
Kaggle SAP Dataset CSV โ SQLite DB ์ด๊ธฐํ ์คํฌ๋ฆฝํธ
"""
import sqlite3
import pandas as pd
from pathlib import Path
DB_PATH = "data/sap_erp.db"
RAW_DIR = "data/raw"
TABLE_CSV_MAP = {
"VBAK": "vbak.csv", # ์์
์ค๋ ํค๋
"VBAP": "vbap.csv", # ์์
์ค๋ ์์ดํ
"VBEP": "vbep.csv", # ๋ฉํ ์ผ์
"VBUK": "vbuk.csv", # ์ค๋ ์ํ (ํค๋)
"VBUP": "vbup.csv", # ์ค๋ ์ํ (์์ดํ
)
"MAKT": "makt.csv", # ์์ฌ ํ
์คํธ
"MARD": "mard.csv", # ์ฌ๊ณ ์ ๋ณด
}
def setup_db(raw_dir: str = RAW_DIR, db_path: str = DB_PATH) -> None:
"""CSV ํ์ผ์ ์ฝ์ด SQLite์ ํ
์ด๋ธ๋ก ๋ก๋ (๊ธฐ์กด ํ
์ด๋ธ ๋ฎ์ด์ฐ๊ธฐ)"""
Path(db_path).parent.mkdir(parents=True, exist_ok=True)
conn = sqlite3.connect(db_path)
for table_name, csv_file in TABLE_CSV_MAP.items():
csv_path = Path(raw_dir) / csv_file
if not csv_path.exists():
print(f"[SKIP] {csv_file} not found")
continue
df = pd.read_csv(csv_path)
df.to_sql(table_name, conn, if_exists="replace", index=False)
print(f"[OK] {table_name}: {len(df)} rows loaded")
conn.close()
print(f"[DONE] SQLite DB created: {db_path}")
if __name__ == "__main__":
setup_db()
|