Ejemplo n.º 1
0
 protected function run1($stage)
 {
     if (!$this->hasTagRole()) {
         $this->console->out("Adding Role tag...");
         $tagRole = TagEntity::findPk(TagEntity::TAG_ID_ROLE) ?: new TagEntity();
         $tagRole->tagId = TagEntity::TAG_ID_ROLE;
         $tagRole->name = 'Role';
         $tagRole->save();
     }
     if (!$this->hasTagRoleBehavior()) {
         $this->console->out("Adding Role behavior tag...");
         $tagRoleBehavior = TagEntity::findPk(TagEntity::TAG_ID_ROLE_BEHAVIOR) ?: new TagEntity();
         $tagRoleBehavior->tagId = TagEntity::TAG_ID_ROLE_BEHAVIOR;
         $tagRoleBehavior->name = 'Role behavior';
         $tagRoleBehavior->save();
     }
     if (!$this->hasTagFarmOwner()) {
         $this->console->out("Adding Farm owner tag...");
         $tagFarmOwner = TagEntity::findPk(TagEntity::TAG_ID_FARM_OWNER) ?: new TagEntity();
         $tagFarmOwner->tagId = TagEntity::TAG_ID_FARM_OWNER;
         $tagFarmOwner->name = 'Farm owner';
         $tagFarmOwner->save();
     }
 }
Ejemplo n.º 2
0
 protected function run1($stage)
 {
     if (!$this->hasTable('farm_usage_d')) {
         $this->console->out("Creating farm_usage_d table...");
         $this->db->Execute("\n                CREATE TABLE IF NOT EXISTS `farm_usage_d` (\n                  `account_id` INT(11) NOT NULL COMMENT 'scalr.clients.id ref',\n                  `farm_role_id` INT(11) NOT NULL COMMENT 'scalr.farm_roles.id ref',\n                  `instance_type` VARCHAR(45) NOT NULL COMMENT 'Type of the instance',\n                  `cc_id` BINARY(16) NOT NULL DEFAULT '' COMMENT 'scalr.ccs.cc_id ref',\n                  `project_id` BINARY(16) NOT NULL DEFAULT '' COMMENT 'scalr.projects.project_id ref',\n                  `date` DATE NOT NULL COMMENT 'UTC Date',\n                  `platform` VARCHAR(20) NOT NULL COMMENT 'cloud platform',\n                  `cloud_location` VARCHAR(255) NOT NULL COMMENT 'cloud location',\n                  `env_id` INT(11) NOT NULL COMMENT 'scalr.client_account_environments.id ref',\n                  `farm_id` INT(11) NOT NULL COMMENT 'scalr.farms.id ref',\n                  `role_id` INT(11) NOT NULL COMMENT 'scalr.roles.id ref',\n                  `cost` DECIMAL(12,6) NOT NULL DEFAULT 0.000000 COMMENT 'total usage',\n                  `min_instances` SMALLINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'min instances count',\n                  `max_instances` SMALLINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'max instances count',\n                  `instance_hours` SMALLINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'total instance hours',\n                  `working_hours` SMALLINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'hours when farm is running',\n                  PRIMARY KEY (`account_id`, `farm_role_id`, `instance_type`, `cc_id`, `project_id`, `date`),\n                  INDEX `idx_farm_role_id` (`farm_role_id` ASC),\n                  INDEX `idx_instance_type` (`instance_type` ASC),\n                  INDEX `idx_date` (`date` ASC),\n                  INDEX `idx_farm_id` (`farm_id` ASC),\n                  INDEX `idx_env_id` (`env_id` ASC),\n                  INDEX `idx_cloud_location` (`cloud_location` ASC),\n                  INDEX `idx_platform` (`platform` ASC),\n                  INDEX `idx_role_id` (`role_id` ASC),\n                  INDEX `idx_project_id` (`project_id` ASC))\n                ENGINE = InnoDB\n                COMMENT = 'Farm daily usage' PARTITION BY HASH(account_id) PARTITIONS 100\n            ");
     }
     if ($this->idxNameNoSubpart) {
         $this->console->out("Modifying index idx_name of prices table...");
         $this->db->Execute("\n                ALTER TABLE `prices`\n                    DROP INDEX `idx_name` ,\n                    ADD INDEX `idx_name` USING BTREE (`name`(3) ASC)\n            ");
     }
     if (!$this->envIdAfterCost) {
         $this->console->out("Moving env_id column just after cost column for usage_d table...");
         $this->db->Execute("\n                ALTER TABLE `usage_d`\n                    CHANGE COLUMN `env_id` `env_id` INT(11) NOT NULL DEFAULT 0\n                    COMMENT 'ID of the environment' AFTER `cost`\n            ");
     }
     if (!$this->hasTableColumn('usage_h', 'role_id')) {
         $this->console->out("Adding role_id column to usage_h table...");
         $this->db->Execute("\n                ALTER TABLE `usage_h`\n                    ADD COLUMN `role_id` INT(11) NULL DEFAULT NULL COMMENT 'scalr.roles.id ref' AFTER `farm_role_id`,\n                    ADD INDEX `idx_role` (`role_id` ASC)\n            ");
     }
     if (!$this->hasTagRole()) {
         $this->console->out("Adding Role tag...");
         $tagRole = TagEntity::findPk(TagEntity::TAG_ID_ROLE) ?: new TagEntity();
         $tagRole->tagId = TagEntity::TAG_ID_ROLE;
         $tagRole->name = 'Role';
         $tagRole->save();
     }
     if (!$this->hasTagRoleBehavior()) {
         $this->console->out("Adding Role behavior tag...");
         $tagRoleBehavior = TagEntity::findPk(TagEntity::TAG_ID_ROLE_BEHAVIOR) ?: new TagEntity();
         $tagRoleBehavior->tagId = TagEntity::TAG_ID_ROLE_BEHAVIOR;
         $tagRoleBehavior->name = 'Role behavior';
         $tagRoleBehavior->save();
     }
 }