數據統計完整設計

數據統計思惟導圖與數據庫設計

爲了知足上大數據達到高效率統計,特別設計一套高性能統計思惟導圖與數據庫設計
  1. 文檔說明
  2. 需求腦圖
  3. 數據庫表結構說明
  4. Yii數據庫遷移文件

文檔說明

點擊查看文檔說明sql

需求腦圖

百度腦圖
雷達統計.png數據庫

數據庫表結構說明

百度腦圖緩存

boss雷達數據庫-微服務.png

遷移文件

/**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('boss_static', [
            'service_key' => $this->char(32)->notNull()->comment('服務祕鑰'),
            'expires_at' => $this->integer()->notNull()->defaultValue(0)->unsigned()->comment('有效期:0永久'),
            'name' => $this->string(30)->notNull()->comment('服務名稱'),
            'created_at' => $this->integer()->notNull()->unsigned()->comment('建立時間'),
            'deleted_at' => $this->integer()->notNull()->defaultValue(0)->unsigned()->comment('刪除時間'),
            'static_count' => $this->bigInteger(12)->notNull()->defaultValue(0)->unsigned()->comment('統計次數'),
            'select_count' => $this->bigInteger(12)->notNull()->defaultValue(0)->unsigned()->comment('查詢次數'),
            'status' => $this->tinyInteger(1)->notNull()->defaultValue(0)->unsigned()->comment('狀態'),
        ]);
        $this->addCommentOnTable('boss_static', '服務申請表');
        $this->addPrimaryKey('primary_service_key', 'boss_static', 'service_key');
        $this->createIndex('idx_created_at', 'boss_static', 'created_at');
        $this->createIndex('idx_deleted_at', 'boss_static', 'deleted_at');

        $this->createTable('boss_static_project', [
            'project_id' => $this->bigPrimaryKey()->comment('統計項目id'),
            'name' => $this->string(20)->notNull()->comment('項目名稱'),
            'service_key' => $this->char(32)->notNull()->comment('服務祕鑰'),
            'created_at' => $this->integer()->notNull()->unsigned()->comment('建立時間'),
            'deleted_at' => $this->integer()->notNull()->defaultValue(0)->unsigned()->comment('刪除時間'),
            'static_count' => $this->bigInteger(12)->notNull()->defaultValue(0)->unsigned()->comment('統計次數'),
            'select_count' => $this->bigInteger(12)->notNull()->defaultValue(0)->unsigned()->comment('查詢次數'),
        ]);
        $this->addCommentOnTable('boss_static_project', '統計項目表');
        $this->createIndex('idx_service_key', 'boss_static_project', 'service_key');
        $this->createIndex('idx_created_at', 'boss_static_project', 'created_at');
        $this->createIndex('idx_deleted_at', 'boss_static_project', 'deleted_at');

        $this->createTable('boss_static_condition', [
            'condition_id' => $this->bigPrimaryKey()->comment('條件id'),
            'service_key' => $this->char(32)->notNull()->comment('服務祕鑰'),
            'project_id' => $this->bigInteger()->notNull()->unsigned()->comment('統計項目id'),
            'key' => $this->string(30)->notNull()->comment('條件字段'),
            'field_type' => $this->tinyInteger()->notNull()->comment('字段類型'),        ]);
        $this->addCommentOnTable('boss_static_condition', '雷達統計條件表');
        $this->createIndex('idx_service_key', 'boss_static_condition', 'service_key');
        $this->createIndex('idx_project_id', 'boss_static_condition', 'project_id');
        $this->createIndex('idx_key', 'boss_static_condition', 'key');
        $this->createIndex('idx_key_field_type', 'boss_static_condition', ['key', 'field_type']);

        $this->createTable('boss_static_condition_tinyint', [
            'condition_id' => $this->bigInteger()->notNull()->unsigned()->comment('條件id'),
            'value' => $this->tinyInteger()->notNull()->unsigned()->comment('值'),
        ]);
        $this->addCommentOnTable('boss_static_condition_tinyint', '短整形');
        $this->addPrimaryKey('primary_condition_id_value', 'boss_static_condition_tinyint', ['condition_id', 'value']);

        $this->createTable('boss_static_condition_bigint', [
            'condition_id' => $this->bigInteger()->notNull()->unsigned()->comment('條件id'),
            'value' => $this->bigInteger(11)->notNull()->unsigned()->comment('值'),
        ]);
        $this->addCommentOnTable('boss_static_condition_bigint', '長整形');
        $this->addPrimaryKey('primary_condition_id_value', 'boss_static_condition_bigint', ['condition_id', 'value']);

        $this->createTable('boss_static_condition_min_varchar', [
            'condition_id' => $this->bigInteger()->notNull()->unsigned()->comment('條件id'),
            'value' => $this->string(50)->notNull()->comment('值'),
        ]);
        $this->addCommentOnTable('boss_static_condition_min_varchar', '短字符串');
        $this->addPrimaryKey('primary_condition_id_value', 'boss_static_condition_min_varchar', ['condition_id', 'value']);

        $this->createTable('boss_static_condition_max_varchar', [
            'condition_id' => $this->bigInteger()->notNull()->unsigned()->comment('條件id'),
            'value' => $this->string(200)->notNull()->comment('值'),
        ]);
        $this->addCommentOnTable('boss_static_condition_max_varchar', '長字符串');
        $this->addPrimaryKey('primary_condition_id_value', 'boss_static_condition_max_varchar', ['condition_id', 'value']);

        $this->createTable('boss_static_hour', [
            'id' => $this->bigPrimaryKey()->comment('小時統計主鍵'),
            'service_key' => $this->char(32)->notNull()->comment('服務祕鑰'),
            'created_at' => $this->integer()->notNull()->unsigned()->comment('首次統計建立時間'),
            'last_update' => $this->integer()->notNull()->unsigned()->comment('最
近一次更新統計時間'),
            'date' => $this->date()->notNull()->comment('當天日期'),
            'hour' => $this->tinyInteger(2)->notNull()->unsigned()->comment('統計
小時'),
            'project_id' => $this->bigInteger()->notNull()->unsigned()->comment('統計項目'),
            'value' => $this->bigInteger(18)->notNull()->unsigned()->defaultValue(0)->comment('統計值'),
        ]);
        $this->addCommentOnTable('boss_static_hour', '雷達統計小時表');
        $this->createIndex('idx_service_key', 'boss_static_hour', 'service_key');        $this->createIndex('idx_date', 'boss_static_hour', ['date']);
        $this->createIndex('idx_date_hour', 'boss_static_hour', ['date', 'hour']);
        $this->createIndex('idx_project_id', 'boss_static_hour', ['project_id']);
        $this->createTable('boss_static_date', [
            'id' => $this->bigPrimaryKey()->comment('日期統計主鍵'),
            'service_key' => $this->char(32)->notNull()->comment('服務祕鑰'),
            'created_at' => $this->integer()->notNull()->unsigned()->comment('首次統計建立時間'),
            'last_update' => $this->integer()->notNull()->unsigned()->comment('最
近一次更新統計時間'),
            'date' => $this->date()->notNull()->comment('當天日期'),
            'project_id' => $this->bigInteger()->notNull()->unsigned()->comment('統計項目'),
            'value' => $this->bigInteger(18)->notNull()->unsigned()->defaultValue(0)->comment('統計值'),
        ]);
        $this->addCommentOnTable('boss_static_date', '雷達統計日期表');
        $this->createIndex('idx_service_key', 'boss_static_date', 'service_key');        $this->createIndex('idx_date', 'boss_static_date', ['date']);
        $this->createIndex('idx_project_id', 'boss_static_date', ['project_id']);
        $this->createTable('boss_static_foreign', [
            'foreign_id' => $this->bigInteger()->comment('關聯id'),
            'foreign_type' => $this->tinyInteger()->notNull()->unsigned()->comment('關聯類型'),
            'foreign_name' => $this->string(20)->notNull()->comment('關聯名稱'),
            'created_at' => $this->integer()->notNull()->comment('關聯時間'),
            'value' => $this->bigInteger(18)->notNull()->unsigned()->defaultValue(0)->comment('統計值'),
        ]);
        $this->addCommentOnTable('boss_static_foreign', '雷達統計關聯表');
        $this->addPrimaryKey('primary_foreign_id_foreign_type_foreign_name', 'boss_static_foreign', ['foreign_id', 'foreign_type', 'foreign_name']);
        $this->createIndex('idx_created_at', 'boss_static_foreign', 'created_at');

        $this->createTable('boss_static_cache', [
            'sql_md5' => $this->char(32)->notNull()->comment('sql語句md5'),
            'cache_version' => $this->string(30)->notNull()->comment('緩存版本'),            'data' => $this->getDb()->getSchema()->createColumnSchemaBuilder('longtext')->comment('緩存結果'),
        ]);
        $this->addCommentOnTable('boss_static_cache', '統計緩存');
        $this->addPrimaryKey('primary_sql_md5_cache_version', 'boss_static_cache', ['sql_md5', 'cache_version']);

    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable('boss_static');
        $this->dropTable('boss_static_project');
        $this->dropTable('boss_static_condition');
        $this->dropTable('boss_static_condition_tinyint');
        $this->dropTable('boss_static_condition_bigint');
        $this->dropTable('boss_static_condition_min_varchar');
        $this->dropTable('boss_static_condition_max_varchar');
        $this->dropTable('boss_static_hour');
        $this->dropTable('boss_static_date');
        $this->dropTable('boss_static_foreign');
        $this->dropTable('boss_static_cache');
    }
相關文章
相關標籤/搜索