Migrate.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. use Schema\Wrapper as Wrapper;
  3. use App\Core\Sanity\MigratorController as Migrator;
  4. function geo_city_upgrade($pluginversion) {
  5. if ($pluginversion < "0.0.1") {
  6. $table = Wrapper::get_table("geo_cities");
  7. $table->addColumn("state_id", "integer", Array("null" => false));
  8. $table->addColumn("country_id", "integer", Array("null" => false));
  9. $table->addColumn("code", "integer", Array("null" => true));
  10. $table->addColumn("name", "string", Array("null" => false));
  11. $table->addColumn("description", "text", Array("null" => true));
  12. $table->addTimestamps();
  13. $table->addSoftDelete();
  14. $table->addForeignKey('state_id', Wrapper::get_table('geo_states'));
  15. $table->addForeignKey('country_id', Wrapper::get_table('geo_countries'));
  16. $table->create();
  17. Wrapper::exec(file_get_contents(__DIR__.'/001_seed_rs_cities.sql') );
  18. Migrator::getInstance()->update_plugin_version("geo_city", "1.0.0");
  19. return;
  20. }
  21. //if ($pluginversion < "0.0.2") {
  22. //$table = Wrapper::get_table("geo_city");
  23. //Migrator::getInstance()->update_plugin_version("geo_city", "1.0.1");
  24. //return;
  25. //}
  26. }
  27. function geo_city_rollback($pluginversion) {
  28. if($pluginversion > "0.0.1"){
  29. $table = Wrapper::get_table("geo_cities");
  30. $table->drop();
  31. return;
  32. }
  33. }