数据统计完整设计

数据统计思维导图与数据库设计

 为了满足上大数据达到高效率统计,特别设计一套高性能统计思维导图与数据库设计       
  1. 文档说明
  2. 需求脑图
  3. 数据库表结构说明
  4. Yii数据库迁移文件

文档说明

点击查看文档说明

需求脑图

百度脑图
雷达统计.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');
    }

你可能感兴趣的:(mysql,数据库,统计分析,php,yii)