Skip to content

Commit

Permalink
make sure init_data can be re-applied with no errors
Browse files Browse the repository at this point in the history
  • Loading branch information
proditis committed Nov 12, 2024
1 parent 6822306 commit 7bb2d92
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 94 deletions.
81 changes: 40 additions & 41 deletions backend/migrations-init/m200309_075759_populate_levels.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,48 @@
*/
class m200309_075759_populate_levels extends Migration
{
public $experiences=[
['name'=>'New', 'description'=>'User just started', 'icon'=> 'default.png'],
['name'=>'Securitas', 'description'=>'test', 'icon'=> 'default.png'],
['name'=>'PenTester', 'description'=>'test', 'icon'=> 'default.png'],
['name'=>'CTFer', 'description'=>'test', 'icon'=> 'default.png'],
['name'=>'Hax0r', 'description'=>'test', 'icon'=> 'default.png'],
public $experiences = [
['name' => 'New', 'description' => 'User just started', 'icon' => 'default.png'],
['name' => 'Securitas', 'description' => 'test', 'icon' => 'default.png'],
['name' => 'PenTester', 'description' => 'test', 'icon' => 'default.png'],
['name' => 'CTFer', 'description' => 'test', 'icon' => 'default.png'],
['name' => 'Hax0r', 'description' => 'test', 'icon' => 'default.png'],
];
/**
* {@inheritdoc}
*/
public function safeUp()
{
$min_points=0;
$max_points=1000;
$step=1000;
$dyn=1;
$lvl=0;
for($i=0;$i < 20;$i++)
{
$xp=[];
$xp['id']=intval($i + 1);
$xp['name']=sprintf("%s %d", $this->experiences[$lvl]['name'], ($dyn % 5));
$xp['category']=sprintf("%s", $this->experiences[$lvl]['name']);
$xp['description']='autogen';
$xp['icon']='default.png';
$xp['min_points']=intval($min_points);
$xp['max_points']=intval($max_points + ($step * ($i == 0 ? $i : $i + 1)));
$this->db->createCommand()->insert('{{%experience}}', $xp)->execute();
$max_points=$xp['max_points'];
$min_points=$max_points + 1;
if(($dyn % 4) == 0)
{
$lvl++;$dyn=0;}
$dyn++;
/**
* {@inheritdoc}
*/
public function safeUp()
{
$min_points = 0;
$max_points = 1000;
$step = 1000;
$dyn = 1;
$lvl = 0;
for ($i = 0; $i < 20; $i++) {
$xp = [];
$xp['id'] = intval($i + 1);
$xp['name'] = sprintf("%s %d", $this->experiences[$lvl]['name'], ($dyn % 5));
$xp['category'] = sprintf("%s", $this->experiences[$lvl]['name']);
$xp['description'] = 'autogen';
$xp['icon'] = 'default.png';
$xp['min_points'] = intval($min_points);
$xp['max_points'] = intval($max_points + ($step * ($i == 0 ? $i : $i + 1)));
$this->upsert('{{%experience}}', $xp);
$max_points = $xp['max_points'];
$min_points = $max_points + 1;
if (($dyn % 4) == 0) {
$lvl++;
$dyn = 0;
}
$dyn++;
}
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->db->createCommand()->truncateTable('{{%experience}}')->execute();
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->db->createCommand()->truncateTable('{{%experience}}')->execute();
}
}
7 changes: 3 additions & 4 deletions backend/migrations-init/m200309_081940_populate_countries.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class m200309_081940_populate_countries extends Migration
*/
public function safeUp()
{
$CREATE_SQL="INSERT INTO country VALUES ('UNK', 'Not set');
INSERT INTO country VALUES ('AF','Afghanistan'),
$CREATE_SQL="INSERT IGNORE INTO country VALUES ('UNK', 'Not set');
INSERT IGNORE INTO country VALUES ('AF','Afghanistan'),
('AL','Albania'),('DZ','Algeria'),('AS','American Samoa'),('AD','Andorra'),('AO','Angola'),
('AI','Anguilla'),('AQ','Antarctica'),('AG','Antigua and Barbuda'),('AR','Argentina'),
('AM','Armenia'),('AW','Aruba'),('AU','Australia'),('AT','Austria'),('AZ','Azerbaijan'),
Expand Down Expand Up @@ -81,8 +81,7 @@ public function safeUp()
('GB','United Kingdom'),('US','United States'),('UM','United States Minor Outlying Islands'),
('UY','Uruguay'),('UZ','Uzbekistan'),('VU','Vanuatu'),('VE','Venezuela'),('VN','Viet Nam'),
('VG','Virgin Islands, British'),('VI','Virgin Islands, U.s.'),('WF','Wallis and Futuna'),
('EH','Western Sahara'),('YE','Yemen'),('ZM','Zambia'),('ZW','Zimbabwe');
";
('EH','Western Sahara'),('YE','Yemen'),('ZM','Zambia'),('ZW','Zimbabwe')";
$this->db->createCommand($CREATE_SQL)->execute();

}
Expand Down
55 changes: 7 additions & 48 deletions backend/migrations-init/m200309_082230_populate_avatars.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,13 @@ class m200309_082230_populate_avatars extends Migration
*/
public function safeUp()
{
$CREATE_SQL="INSERT INTO avatar value ('256_10.png');
INSERT INTO avatar value ('256_11.png');
INSERT INTO avatar value ('256_12.png');
INSERT INTO avatar value ('256_13.png');
INSERT INTO avatar value ('256_14.png');
INSERT INTO avatar value ('256_15.png');
INSERT INTO avatar value ('256_16.png');
INSERT INTO avatar value ('256_1.png');
INSERT INTO avatar value ('256_2.png');
INSERT INTO avatar value ('256_3.png');
INSERT INTO avatar value ('256_4.png');
INSERT INTO avatar value ('256_5.png');
INSERT INTO avatar value ('256_6.png');
INSERT INTO avatar value ('256_7.png');
INSERT INTO avatar value ('256_8.png');
INSERT INTO avatar value ('256_9.png');
INSERT INTO avatar value ('avatar-1.png');
INSERT INTO avatar value ('avatar-2.png');
INSERT INTO avatar value ('avatar-3.png');
INSERT INTO avatar value ('avatar-4.png');
INSERT INTO avatar value ('avatar-5.png');
INSERT INTO avatar value ('avatar-6.png');
INSERT INTO avatar value ('avatar-7.png');
INSERT INTO avatar value ('avatar-8.png');
INSERT INTO avatar value ('Bride.png');
INSERT INTO avatar value ('default.png');
INSERT INTO avatar value ('Franky.png');
INSERT INTO avatar value ('Skeleton.png');
INSERT INTO avatar value ('users-10.svg');
INSERT INTO avatar value ('users-11.svg');
INSERT INTO avatar value ('users-12.svg');
INSERT INTO avatar value ('users-13.svg');
INSERT INTO avatar value ('users-14.svg');
INSERT INTO avatar value ('users-15.svg');
INSERT INTO avatar value ('users-16.svg');
INSERT INTO avatar value ('users-1.svg');
INSERT INTO avatar value ('users-2.svg');
INSERT INTO avatar value ('users-3.svg');
INSERT INTO avatar value ('users-4.svg');
INSERT INTO avatar value ('users-5.svg');
INSERT INTO avatar value ('users-6.svg');
INSERT INTO avatar value ('users-7.svg');
INSERT INTO avatar value ('users-8.svg');
INSERT INTO avatar value ('users-9.svg');
INSERT INTO avatar value ('Vampire-Girl.png');
INSERT INTO avatar value ('Vampire.png');
INSERT INTO avatar value ('Witch.png');
";
$CREATE_SQL="INSERT IGNORE INTO avatar value ('256_10.png'),('256_11.png'),('256_12.png'),('256_13.png'),('256_14.png'),
('256_15.png'),('256_16.png'), ('256_1.png'), ('256_2.png'), ('256_3.png'), ('256_4.png'), ('256_5.png'), ('256_6.png'),
('256_7.png'), ('256_8.png'), ('256_9.png'), ('avatar-1.png'), ('avatar-2.png'), ('avatar-3.png'), ('avatar-4.png'), ('avatar-5.png'),
('avatar-6.png'), ('avatar-7.png'), ('avatar-8.png'), ('Bride.png'), ('default.png'), ('Franky.png'),
('Skeleton.png'), ('users-10.svg'), ('users-11.svg'), ('users-12.svg'), ('users-13.svg'), ('users-14.svg'), ('users-15.svg'),
('users-16.svg'), ('users-1.svg'), ('users-2.svg'), ('users-3.svg'), ('users-4.svg'), ('users-5.svg'), ('users-6.svg'),
('users-7.svg'), ('users-8.svg'), ('users-9.svg'), ('Vampire-Girl.png'), ('Vampire.png'), ('Witch.png')";
$this->db->createCommand($CREATE_SQL)->execute();
}

Expand Down
2 changes: 1 addition & 1 deletion backend/migrations-init/m200309_094731_populate_hints.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class m200309_094731_populate_hints extends Migration
*/
public function safeUp()
{
$this->db->createCommand("insert into hint (id,title) values (-1,'Welcome to the gig')")->execute();
$this->upsert("hint",['id'=>-1,'title'=>'Welcome to the gig']);

}

Expand Down

0 comments on commit 7bb2d92

Please sign in to comment.