/**
  * @param bool $clean
  * @return DBTestCreator
  * @throws DatabaseException
  */
 public function dropDB($clean = false)
 {
     foreach ($this->pool->getPool() as $name => $db) {
         /* @var $db DB */
         foreach ($this->schema->getTableNames() as $name) {
             try {
                 $db->queryRaw(OSQL::dropTable($name, true)->toDialectString($db->getDialect()));
             } catch (DatabaseException $e) {
                 if (!$clean) {
                     throw $e;
                 }
             }
             if ($db->hasSequences()) {
                 foreach ($this->schema->getTableByName($name)->getColumns() as $columnName => $column) {
                     try {
                         if ($column->isAutoincrement()) {
                             $db->queryRaw("DROP SEQUENCE {$name}_id;");
                         }
                     } catch (DatabaseException $e) {
                         if (!$clean) {
                             throw $e;
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
    /**
     * Dumps schema
     *
     * @param IOutput $writeStream stream to write the dump to
     * @param IDialect $dialect database dialect to use
     *
     * @return void
     */
    function make(IOutput $writeStream, IDialect $dialect)
    {
        $now = date('Y/m/d H:i');
        $product = PHOEBIUS_FULL_PRODUCT_NAME;
        $start = <<<EOT
--
-- {$product}
-- Generated at {$now} for {$dialect->getDBDriver()->getValue()}
--


EOT;
        $writeStream->write($start)->write($this->dbSchema->toDialectString($dialect));
    }
Exemplo n.º 3
0
 /**
  * Applies a diff to the specified schema
  * @param DBSchema $schema
  * @return DBDiff itself
  */
 function apply(DBSchema $schema)
 {
     foreach ($this->createTables as $table) {
         $schema->addTable($table);
     }
     foreach ($this->createColumns as $column) {
         $schema->getTable($column->getTable()->getName())->addColumn($column);
     }
     foreach ($this->createConstraints as $constaint) {
         $schema->getTable($constaint->getTable()->getName())->addConstraint($constaint);
     }
     foreach ($this->createIndexes as $index) {
         $schema->getTable($index->getTable()->getName())->addIndex($index);
     }
     return $this;
 }
 function doUp()
 {
     global $database;
     if (DBSchema::existsIndex($database, 'SurveyTemplate', 'Title')) {
         DB::query('ALTER TABLE SurveyTemplate DROP INDEX Title;');
     }
 }
 /**
  * Run the migration
  */
 public function doUp()
 {
     global $database;
     if (DBSchema::existsColumn($database, 'PresentationVideo', 'Processed')) {
         DB::query("UPDATE PresentationVideo SET Processed = 1");
     }
 }
 function doUp()
 {
     global $database;
     if (DBSchema::existsColumn($database, 'SummitRegistrationPromoCode', 'OwnerID')) {
         DBSchema::dropColumn($database, 'SummitRegistrationPromoCode', 'OwnerID');
     }
 }
 function doUp()
 {
     global $database;
     if (DBSchema::existsColumn($database, "EventbriteEvent", "ExternalOrderId")) {
         DBSchema::dropColumn($database, "EventbriteEvent", "ExternalOrderId");
     }
 }
 /**
  * Run the migration
  */
 public function doUp()
 {
     global $database;
     if (DBSchema::existsColumn($database, 'GerritChangeInfo', 'MemberID')) {
         DBSchema::dropColumn($database, 'GerritChangeInfo', 'MemberID');
     }
 }
Exemplo n.º 9
0
 private function importConstraints(OrmProperty $property)
 {
     $name = $this->dbTable->getName() . '_' . $property->getName();
     $fields = $property->getFields();
     if ($property->isIdentifier()) {
         $this->dbTable->addConstraint(new DBPrimaryKeyConstraint($name . '_pk', $this->dbTable, $fields));
     } else {
         if ($property->isUnique()) {
             $this->dbTable->addConstraint(new DBUniqueConstraint($name . '_uq', $this->dbTable, $fields));
         }
     }
     $type = $property->getType();
     if ($type instanceof AssociationPropertyType) {
         $this->dbTable->addConstraint(new DBOneToOneConstraint($name . '_fk', $this->dbTable, $fields, $this->dbSchema->getTable($property->getType()->getContainer()->getTable()), $property->getType()->getAssociationBreakAction()));
     } else {
         if ($type instanceof CompositePropertyType) {
             foreach ($type->getProperties($property) as $_property) {
                 $this->importConstraints($_property);
             }
         }
     }
     if ($property->isQueryable()) {
         $this->dbTable->addIndex(new DBIndex($name . '_idx', $this->dbTable, $fields));
     }
 }
 function doUp()
 {
     global $database;
     if (DBSchema::existsColumn($database, 'SummitPresentationComment', 'IsCategoryChangeSuggestion')) {
         DB::query("UPDATE SummitPresentationComment set IsCategoryChangeSuggestion = 1\nWHERE Body LIKE '%suggested that this presentation be moved to the category%';");
     }
 }
    function doUp()
    {
        global $database;
        if (DBSchema::existsColumn($database, 'PresentationSpeaker', 'OnSitePhoneNumber')) {
            $speakers_info_query = <<<SQL
SELECT ID, OnSitePhoneNumber, ConfirmedDate, RegisteredForSummit
FROM PresentationSpeaker where OnSitePhoneNumber IS NOT NULL;
SQL;
            $res = DB::query($speakers_info_query);
            foreach ($res as $row) {
                $speaker_id = intval($row['ID']);
                $on_site_phone = intval($row['OnSitePhoneNumber']);
                $confirmed_date = $row['ConfirmedDate'];
                $registered = (bool) $row['RegisteredForSummit'];
                $speaker = PresentationSpeaker::get()->byID($speaker_id);
                if (is_null($speaker)) {
                    continue;
                }
                if (PresentationSpeakerSummitAssistanceConfirmationRequest::get()->filter(array('SummitID' => 5, 'SpeakerID' => $speaker_id))->count() > 0) {
                    continue;
                }
                $assistance = PresentationSpeakerSummitAssistanceConfirmationRequest::create();
                $assistance->SpeakerID = $speaker_id;
                $assistance->SummitID = 5;
                $assistance->OnSitePhoneNumber = $on_site_phone;
                $assistance->ConfirmationDate = $confirmed_date;
                $assistance->RegisteredForSummit = $registered;
                $assistance->IsConfirmed = true;
                $assistance->write();
            }
            DBSchema::dropColumn($database, 'PresentationSpeaker', 'OnSitePhoneNumber');
            DBSchema::dropColumn($database, 'PresentationSpeaker', 'ConfirmedDate');
            DBSchema::dropColumn($database, 'PresentationSpeaker', 'RegisteredForSummit');
        }
    }
 function doUp()
 {
     global $database;
     if (DBSchema::existsIndex($database, 'SummitAttendee', 'Summit_Member')) {
         DBSchema::dropIndex($database, 'SummitAttendee', 'Summit_Member');
     }
 }
 function doUp()
 {
     global $database;
     if (DBSchema::existsColumn($database, 'Member', 'LegacyMember')) {
         DB::query("UPDATE Member SET LegacyMember = 1 ;");
         DB::query("UPDATE Member SET EmailVerified = 1, EmailVerifiedDate = NOW() WHERE LegacyMember = 1;");
     }
 }
 function doUp()
 {
     global $database;
     if (DBSchema::existsTable($database, 'Presentation_Tags')) {
         DB::query("INSERT INTO SummitEvent_Tags (SummitEventID, TagID) select PresentationID, TagID from Presentation_Tags;");
         DB::query("DROP TABLE Presentation_Tags;");
         DB::query("UPDATE SummitEvent INNER JOIN Presentation ON Presentation.ID = SummitEvent.ID SET SummitEvent.ShortDescription = Presentation.ShortDescription;");
         DB::query("ALTER TABLE Presentation DROP COLUMN ShortDescription;");
     }
 }
 function doUp()
 {
     global $database;
     $columns = array('LastEdited', 'Created', 'Name', 'DisplayOnSite', 'Featured', 'City', 'Country', 'YouTubeID', 'URLSegment', 'StartTime', 'EndTime', 'Type', 'Location', 'Day', 'Speakers', 'SlidesLink', 'event_key', 'MemberID', 'IsKeynote');
     foreach ($columns as $column) {
         if (DBSchema::existsColumn($database, 'Presentation', $column)) {
             DB::query("ALTER TABLE Presentation DROP COLUMN {$column};");
         }
     }
 }
 function doUp()
 {
     global $database;
     global $database;
     $columns = array('Name', 'SchedUrl');
     foreach ($columns as $column) {
         if (DBSchema::existsColumn($database, 'Summit', $column)) {
             DB::query("ALTER TABLE Summit DROP COLUMN {$column};");
         }
     }
 }
 public function doUp()
 {
     global $database;
     if (DBSchema::existsColumn($database, 'SummitCategoryChange', 'Done')) {
         DB::query("UPDATE SummitCategoryChange SET Status = 1 WHERE Done=1");
         DB::query("UPDATE SummitCategoryChange SET Status = 0 WHERE Done=0");
     }
     DB::query("UPDATE SummitSelectedPresentation SET Collection = 'selected'");
     if (DBSchema::existsColumn($database, 'SummitPresentationComment', 'IsCategoryChangeSuggestion')) {
         DB::query("UPDATE SummitPresentationComment SET IsActivity = 1 WHERE IsCategoryChangeSuggestion = 1");
     }
 }
 function doUp()
 {
     global $database;
     if (DBSchema::existsColumn($database, 'SummitAttendee', 'TicketTypeID')) {
         DB::query("DELETE FROM SummitAttendee;");
         DB::query("UPDATE EventbriteEvent SET Processed = 0;");
         DB::query("ALTER TABLE SummitAttendee DROP COLUMN TicketTypeID;");
         DB::query("ALTER TABLE SummitAttendee DROP COLUMN ExternalTicketClassID;");
         DB::query("ALTER TABLE SummitAttendee DROP COLUMN ExternalOrderId;");
         DB::query("ALTER TABLE SummitAttendee DROP COLUMN TicketBoughtDate;");
         DB::query("ALTER TABLE SummitAttendee DROP COLUMN ExternalId;");
     }
 }
 /**
  * Run the migration
  */
 public function doUp()
 {
     global $database;
     if (DBSchema::existsColumn($database, 'Member', 'CLASigned')) {
         DBSchema::dropColumn($database, 'Member', 'CLASigned');
     }
     if (DBSchema::existsColumn($database, 'Member', 'GerritID')) {
         DBSchema::dropColumn($database, 'Member', 'GerritID');
     }
     if (DBSchema::existsColumn($database, 'Member', 'LastCodeCommit')) {
         DBSchema::dropColumn($database, 'Member', 'LastCodeCommit');
     }
 }
 function doUp()
 {
     global $database;
     if (!DBSchema::existsColumn($database, 'PresentationSpeaker', 'Expertise')) {
         return;
     }
     $speakers = DB::query("SELECT * FROM PresentationSpeaker WHERE Expertise IS NOT NULL");
     foreach ($speakers as $speaker) {
         $expertise_array = preg_split('/$\\R?^/m', $speaker['Expertise']);
         foreach ($expertise_array as $exp) {
             $new_exp = new SpeakerExpertise();
             $new_exp->Expertise = $exp;
             $new_exp->SpeakerID = $speaker['ID'];
             $new_exp->Write();
         }
     }
     DB::query("ALTER TABLE PresentationSpeaker DROP COLUMN Expertise");
 }
 function doUp()
 {
     global $database;
     if (DBSchema::existsTable($database, '_obsolete_SummitLocationMap')) {
         $res = DB::query("SELECT * FROM _obsolete_SummitLocationMap;");
         foreach ($res as $row) {
             $new_location = SummitLocationMap::create();
             $new_location->Name = trim($row['Name']);
             $new_location->Description = trim($row['Description']);
             $new_location->PictureID = intval($row['MapID']);
             $new_location->LocationID = intval($row['LocationID']);
             $new_location->Created = trim($row['Created']);
             $new_location->LastEdited = trim($row['LastEdited']);
             $new_location->Order = intval($row['Order']);
             $new_location->write();
         }
         DB::query("DROP TABLE _obsolete_SummitLocationMap;");
     }
 }
 function doUp()
 {
     global $database;
     if (DBSchema::existsColumn($database, 'PresentationSpeaker', 'SummitID')) {
         DBSchema::dropColumn($database, 'PresentationSpeaker', 'SummitID');
     }
     if (DBSchema::existsColumn($database, 'PresentationSpeaker', 'AnnouncementEmailTypeSent')) {
         DBSchema::dropColumn($database, 'PresentationSpeaker', 'AnnouncementEmailTypeSent');
     }
     if (DBSchema::existsColumn($database, 'PresentationSpeaker', 'AnnouncementEmailSentDate')) {
         DBSchema::dropColumn($database, 'PresentationSpeaker', 'AnnouncementEmailSentDate');
     }
     if (DBSchema::existsColumn($database, 'PresentationSpeaker', 'SummitRegistrationPromoCodeID')) {
         DBSchema::dropColumn($database, 'PresentationSpeaker', 'SummitRegistrationPromoCodeID');
     }
     if (DBSchema::existsColumn($database, 'PresentationSpeaker', 'TwitterHandle')) {
         DB::query('UPDATE PresentationSpeaker SET TwitterName = TwitterHandle;');
         DBSchema::dropColumn($database, 'PresentationSpeaker', 'TwitterHandle');
     }
 }
 function doUp()
 {
     global $database;
     if (DBSchema::existsTable($database, "JobPage")) {
         $res = DB::query("SELECT * FROM JobPage;");
         foreach ($res as $record) {
             $new_job = new Job();
             $new_job->ID = (int) $record['ID'];
             $new_job->Title = $record['Title'];
             $new_job->Description = $record['Content'];
             $new_job->Created = $record['Created'];
             $new_job->LastEdited = $record['LastEdited'];
             $new_job->PostedDate = $record['JobPostedDate'];
             $new_job->ExpirationDate = $record['ExpirationDate'];
             // company name logic
             $company_name = $record['JobCompany'];
             $company = Company::get()->filter('Name', $company_name)->first();
             $new_job->CompanyID = is_null($company) ? 0 : $company->ID;
             if ($new_job->CompanyID == 0) {
                 $new_job->CompanyName = $company_name;
             }
             $new_job->MoreInfoLink = $record['JobMoreInfoLink'];
             $new_job->Location = $record['JobLocation'];
             $new_job->IsFoundationJob = $record['FoundationJob'];
             $new_job->IsActive = $record['Active'];
             $new_job->Instructions2Apply = $record['JobInstructions2Apply'];
             $new_job->LocationType = $record['LocationType'];
             $new_job->IsCOANeeded = 0;
             $new_job->TypeID = 0;
             //registration request
             $registration_request = JobRegistrationRequest::get()->filter('Title', $new_job->Title)->first();
             if (!is_null($registration_request)) {
                 $new_job->RegistrationRequestID = $registration_request->ID;
             }
             $new_job->write();
         }
         DBSchema::dropTable($database, "JobPage");
     }
 }
Exemplo n.º 24
0
 /**
  * @return void
  */
 private function importProperty()
 {
     if (!sizeof($this->ormProperty->getFields())) {
         // columnless properties are skipped
         return;
     }
     $columns = array_combine($this->ormProperty->getFields(), $this->ormProperty->getType()->getSqlTypes());
     $dbColumns = array();
     foreach ($columns as $name => $dbType) {
         $dbColumns[$name] = new DBColumn($name, $dbType);
     }
     $fields = array_keys($dbColumns);
     $this->dbTable->addColumns($dbColumns);
     if ($this->ormProperty->getType() instanceof AssociationPropertyType) {
         $this->dbTable->addConstraint(new DBOneToOneConstraint($fields, $this->dbSchema->getTable($this->ormProperty->getType()->getContainer()->getTable()), $this->ormProperty->getType()->getAssociationBreakAction()));
     }
     if ($this->ormProperty->isIdentifier()) {
         $this->dbTable->addConstraint(new DBPrimaryKeyConstraint($fields));
     } else {
         if ($this->ormProperty->isUnique()) {
             $this->dbTable->addConstraint(new DBUniqueConstraint($fields));
         }
     }
 }
Exemplo n.º 25
0
 protected static function _in_table($column, $class = null)
 {
     return DBSchema::in(static::_class_to_table($class), $column);
 }
Exemplo n.º 26
0
<?php

/*****************************************************************************
 *   Copyright (C) 2006-2007, onPHP's MetaConfiguration Builder.             *
 *   Generated by onPHP-0.9.128 at 2007-03-31 16:25:48                       *
 *   This file is autogenerated - do not edit.                               *
 *****************************************************************************/
$schema = new DBSchema();
$schema->addTable(DBTable::create('administrator')->addColumn(DBColumn::create(DataType::create(DataType::BIGINT)->setNull(false), 'id')->setPrimaryKey(true)->setAutoincrement(true))->addColumn(DBColumn::create(DataType::create(DataType::VARCHAR)->setNull(false)->setSize(64), 'username'))->addColumn(DBColumn::create(DataType::create(DataType::VARCHAR)->setNull(false)->setSize(40), 'password')));
Exemplo n.º 27
0
<?php

require_once 'php_datamanip/dbschema_parser.inc';
require_once 'php_datamanip/dbschema_phpemitter.inc';
if ($argc != 3) {
    die("Syntax: input.schema output/dir/base_\n");
}
$input = $argv[1];
$output = $argv[2];
$data = file_get_contents($input);
$schema = DBSchema::parse($data);
//var_dump( $schema );
$emit = new DBSchema_PHPEmitter($schema);
$emit->emit($output);
    function doUp()
    {
        global $database;
        if (DBSchema::existsColumn($database, 'Presentation', 'SummitID')) {
            $SQL = <<<SQL
 UPDATE Presentation SET SummitID = 5;
SQL;
            DB::query($SQL);
            DB::query('DELETE FROM SummitEvent;');
            $SQL = <<<SQL

INSERT INTO SummitEvent
(ID, Created, LastEdited, ClassName, Title, Description, SummitID)
SELECT ID, Created, LastEdited, ClassName, Title, Description, SummitID FROM Presentation;
SQL;
            DB::query($SQL);
            $SQL = <<<SQL
ALTER TABLE Presentation
  DROP COLUMN Title,
  DROP COLUMN SummitID,
  DROP COLUMN Description;
SQL;
            DB::query($SQL);
            $SQL = <<<SQL
INSERT INTO SummitAbstractLocation
(ID, ClassName, Created, LastEdited, `Name`, Description, `Order`, SummitID, LocationType)
SELECT ID, 'SummitVenue', Created, LastEdited, `Name` , Description, `Order`,
CASE SummitLocationPageID
WHEN 2345 THEN 4
WHEN 2579 THEN 5
ELSE NULL
END AS SummitID,
'Internal'
from SummitLocation where Type ='Venue';
SQL;
            DB::query($SQL);
            $SQL = <<<SQL
INSERT INTO SummitGeoLocatedLocation
(ID, Address1, WebSiteUrl, Lat, Lng, DisplayOnSite)
SELECT ID,Address, Website, Latitude, Longitude, DisplayOnSite
from SummitLocation where Type ='Venue';
SQL;
            DB::query($SQL);
            $SQL = <<<SQL
INSERT INTO SummitAbstractLocation
(ID, ClassName, Created, LastEdited, `Name`, Description, `Order`, SummitID, LocationType)
SELECT ID, 'SummitHotel', Created, LastEdited, `Name` , Description, `Order`,
CASE SummitLocationPageID
WHEN 2345 THEN 4
WHEN 2579 THEN 5
ELSE 0
END AS SummitID,
'External'
from SummitLocation where Type ='Hotel';
SQL;
            DB::query($SQL);
            $SQL = <<<SQL
INSERT INTO SummitGeoLocatedLocation
(ID, Address1, WebSiteUrl, Lat, Lng, DisplayOnSite)
SELECT ID,Address, Website, Latitude, Longitude, DisplayOnSite
from SummitLocation where Type ='Hotel';
SQL;
            DB::query($SQL);
            $SQL = <<<SQL
INSERT INTO SummitHotel
(ID, BookingLink, SoldOut)
SELECT ID,BookingLink, IsSoldOut
from SummitLocation where Type ='Hotel';
SQL;
            DB::query($SQL);
            $SQL = <<<SQL
INSERT INTO SummitAbstractLocation
(ID, ClassName, Created, LastEdited, `Name`, Description, `Order`, SummitID, LocationType)
SELECT ID, 'SummitAirport', Created, LastEdited, `Name` , Description, `Order`,
CASE SummitLocationPageID
WHEN 2345 THEN 4
WHEN 2579 THEN 5
ELSE 0
END AS SummitID,
'External'
from SummitLocation where Type ='Airport';
SQL;
            DB::query($SQL);
            $SQL = <<<SQL
INSERT INTO SummitGeoLocatedLocation
(ID, Address1, WebSiteUrl, Lat, Lng, DisplayOnSite)
SELECT ID,Address, Website, Latitude, Longitude, DisplayOnSite
from SummitLocation where Type ='Airport';
SQL;
            DB::query($SQL);
            $SQL = <<<SQL
INSERT INTO
SummitAirport
(ID)
SELECT ID from SummitLocation where Type ='Airport';
SQL;
            DB::query($SQL);
        }
    }