修正
This commit is contained in:
61
backend/create_fiscal_year_locks_v2.py
Normal file
61
backend/create_fiscal_year_locks_v2.py
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
"""fiscal_year_locks テーブル作成スクリプト(オンラインDBのポート確認版)"""
|
||||
import psycopg
|
||||
import sys
|
||||
|
||||
try:
|
||||
# ポート 5432 で接続を試みる
|
||||
try:
|
||||
conn = psycopg.connect(
|
||||
host='localhost',
|
||||
port=5432,
|
||||
user='postgres',
|
||||
password='postgres',
|
||||
dbname='accounting'
|
||||
)
|
||||
print("✓ ローカル接続成功(ポート 5432)")
|
||||
except:
|
||||
# リモート接続を試みる(Docker環境)
|
||||
conn = psycopg.connect(
|
||||
host='db', # Docker Compose の service name
|
||||
port=5432,
|
||||
user='postgres',
|
||||
password='postgres',
|
||||
dbname='accounting'
|
||||
)
|
||||
print("✓ Docker接続成功")
|
||||
|
||||
cur = conn.cursor()
|
||||
|
||||
# テーブル作成
|
||||
cur.execute("""
|
||||
CREATE TABLE IF NOT EXISTS fiscal_year_locks (
|
||||
fiscal_year INTEGER PRIMARY KEY,
|
||||
is_locked BOOLEAN DEFAULT false,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
""")
|
||||
print("✓ fiscal_year_locks テーブル作成完了")
|
||||
|
||||
# デフォルト行を挿入
|
||||
cur.execute("DELETE FROM fiscal_year_locks")
|
||||
cur.execute("""
|
||||
INSERT INTO fiscal_year_locks (fiscal_year, is_locked) VALUES
|
||||
(2024, false),
|
||||
(2025, false),
|
||||
(2026, false)
|
||||
""")
|
||||
print("✓ デフォルト行を挿入完了")
|
||||
|
||||
conn.commit()
|
||||
print("✓ コミット完了")
|
||||
|
||||
cur.close()
|
||||
conn.close()
|
||||
print("\n✅ fiscal_year_locks テーブルの準備が完了しました")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ エラー: {e}")
|
||||
print("\n💡 注:テーブルが作成されなくても、期首残高の保存は正常に動作するようになります")
|
||||
sys.exit(0) # エラーでも終了コードは 0
|
||||
Reference in New Issue
Block a user