'commit'
This commit is contained in:
89
DouYin/init_db.py
Normal file
89
DouYin/init_db.py
Normal file
@@ -0,0 +1,89 @@
|
||||
import sys
|
||||
import os
|
||||
# Add project root to path
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import pymysql
|
||||
from Config.Config import DORIS_HOST, DORIS_PORT, DORIS_USER, DORIS_PWD, DORIS_DATABASE
|
||||
|
||||
def init_db():
|
||||
print(f"Connecting to {DORIS_HOST}:{DORIS_PORT}...")
|
||||
try:
|
||||
conn = pymysql.connect(
|
||||
host=DORIS_HOST,
|
||||
port=DORIS_PORT,
|
||||
user=DORIS_USER,
|
||||
password=DORIS_PWD,
|
||||
database=DORIS_DATABASE,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
sql = """
|
||||
CREATE TABLE IF NOT EXISTS t_douyin_record (
|
||||
id VARCHAR(50) NOT NULL COMMENT "UUID",
|
||||
video_name VARCHAR(500) COMMENT "视频名称",
|
||||
original_text TEXT COMMENT "原始粘贴文本",
|
||||
obs_url VARCHAR(500) COMMENT "OBS视频链接",
|
||||
transcript TEXT COMMENT "文案内容",
|
||||
status VARCHAR(20) COMMENT "状态: PROCESSING, COMPLETED, FAILED",
|
||||
create_time DATETIME COMMENT "创建时间"
|
||||
)
|
||||
UNIQUE KEY(id)
|
||||
DISTRIBUTED BY HASH(id) BUCKETS 1
|
||||
PROPERTIES (
|
||||
"replication_allocation" = "tag.location.default: 1"
|
||||
);
|
||||
"""
|
||||
# Note: replication_num is deprecated in newer Doris, using replication_allocation.
|
||||
# If it fails, I will revert to replication_num.
|
||||
|
||||
print("Executing CREATE TABLE...")
|
||||
cursor.execute(sql)
|
||||
print("Table t_douyin_record created (or already exists).")
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
# Try with replication_num if allocation fails
|
||||
if "replication_allocation" in str(e):
|
||||
print("Retrying with replication_num...")
|
||||
try:
|
||||
conn = pymysql.connect(
|
||||
host=DORIS_HOST,
|
||||
port=DORIS_PORT,
|
||||
user=DORIS_USER,
|
||||
password=DORIS_PWD,
|
||||
database=DORIS_DATABASE,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
sql = """
|
||||
CREATE TABLE IF NOT EXISTS t_douyin_record (
|
||||
id VARCHAR(50) NOT NULL COMMENT "UUID",
|
||||
video_name VARCHAR(500) COMMENT "视频名称",
|
||||
original_text TEXT COMMENT "原始粘贴文本",
|
||||
obs_url VARCHAR(500) COMMENT "OBS视频链接",
|
||||
transcript TEXT COMMENT "文案内容",
|
||||
status VARCHAR(20) COMMENT "状态: PROCESSING, COMPLETED, FAILED",
|
||||
create_time DATETIME COMMENT "创建时间"
|
||||
)
|
||||
UNIQUE KEY(id)
|
||||
DISTRIBUTED BY HASH(id) BUCKETS 1
|
||||
PROPERTIES (
|
||||
"replication_num" = "1"
|
||||
);
|
||||
"""
|
||||
cursor.execute(sql)
|
||||
print("Table t_douyin_record created with replication_num.")
|
||||
cursor.close()
|
||||
conn.close()
|
||||
return True
|
||||
except Exception as e2:
|
||||
print(f"Retry Error: {e2}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
init_db()
|
||||
Reference in New Issue
Block a user