#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ # @Version : Python 3.11.4 # @Software : Sublime Text 4 # @Author : StudentCWZ # @Email : StudentCWZ@outlook.com # @Date : 2023/10/29 11:21 # @File : cmdline.py # @Description : Defines the initial command line interface for the Flask application. """ # Import third-party modules import click from flask.cli import with_appcontext from sqlalchemy import text @click.command("init") @with_appcontext def init(): """ Initialize the application by creating a new log entry. This command is to be used with the Flask application context. """ from application.extensions.init_sqlalchemy import db # Uncomment below lines to create a new log entry. click.echo('create tables') with db.app.app_context(): cfg = db.app.config.Database db.session.execute(text(f""" CREATE TABLE IF NOT EXISTS {cfg.TableName} ( id SERIAL NOT NULL, date_time TIMESTAMP WITH TIME ZONE NOT NULL, uuid varchar(100) DEFAULT NULL, mid varchar(50) DEFAULT NULL, mid_type varchar(50) DEFAULT NULL, mac_wifi varchar(50) DEFAULT NULL, mac_voice varchar(50) DEFAULT NULL, code smallint DEFAULT NULL, query varchar(255) DEFAULT NULL, terminal_domain varchar(50) DEFAULT NULL, terminal_intent varchar(50) DEFAULT NULL, distribution_gree_domain varchar(50) DEFAULT NULL, distribution_gree_intent varchar(50) DEFAULT NULL, response_text text, emotion_class varchar(50) DEFAULT NULL, skill_id varchar(100) DEFAULT NULL, voice_portal smallint NOT NULL, service_nlu varchar(50) DEFAULT NULL, service_type smallint NOT NULL, slots text, yzs_request_id varchar(50) DEFAULT NULL, yzs_remote_ip varchar(15) DEFAULT NULL, yzs_app_key varchar(50) DEFAULT NULL, yzs_ud_id varchar(50) DEFAULT NULL, yzs_user_id varchar(50) DEFAULT NULL, yzs_intent text, yzs_general text, yzs_nlu_time varchar(20) DEFAULT NULL, get_body_time varchar(20) DEFAULT NULL, gree_nlu_time varchar(20) DEFAULT NULL, get_homeid_time varchar(20) DEFAULT NULL, tencent_nlu_time varchar(20) DEFAULT NULL, cost_time varchar(20) DEFAULT NULL, PRIMARY KEY (id, date_time) ) PARTITION BY RANGE (date_time); """)) db.session.commit() click.echo('created tables')