public function testAddBehavior()
 {
     $platform = new MysqlPlatform();
     $config = new GeneratorConfig();
     $config->setBuildProperties(array('propel.behavior.timestampable.class' => 'propel.engine.behavior.TimestampableBehavior'));
     $platform->setGeneratorConfig($config);
     $xmlToAppData = new XmlToAppData($platform, "defaultpackage", null);
     $appData = $xmlToAppData->parseFile('fixtures/bookstore/behavior-schema.xml');
     $table = $appData->getDatabase("bookstore-behavior")->getTable('table1');
     $this->assertThat($table->getBehavior('timestampable'), $this->isInstanceOf('TimestampableBehavior'), 'addBehavior() uses the behavior class defined in build.properties');
 }
 /**
  * Get the Platform object for this class
  *
  * @return Platform
  */
 protected function getPlatform()
 {
     static $platform;
     if (!$platform) {
         $platform = new MysqlPlatform();
         $config = new GeneratorConfig();
         $config->setBuildProperties(array('propel.mysql.tableType' => 'InnoDB'));
         $platform->setGeneratorConfig($config);
     }
     return $platform;
 }
    public function testIndex()
    {
        $updatedSchema = '
<database>
  <table name="notification">
    <column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
    <column name="target_user_id" required="true" type="INTEGER" />
    <column name="notification_type_unique_name" required="true" size="255" type="VARCHAR" />
    <column name="group_id" type="INTEGER" />
    <column name="date" required="true" type="TIMESTAMP" />
    <column name="objects" type="LONGVARCHAR" />
    <column name="is_new" defaultValue="1" required="true" type="BOOLEAN" />
    <foreign-key foreignTable="notification_type" name="FK_NOTIFICATION_TYPENOTIFICATION0">
      <reference foreign="unique_name" local="notification_type_unique_name" />
    </foreign-key>
    <index name="FK_NOTIFICATION_TARGET_USER">
      <index-column name="target_user_id" />
    </index>
    <index name="FK_NOTIFICATION_TYPENOTIFICATION">
      <index-column name="notification_type_unique_name" />
    </index>
  </table>
  <table name="notification_type">
    <column name="module_unique_name" primaryKey="true" required="true" size="255" type="VARCHAR" />
    <column name="unique_name" primaryKey="true" required="true" size="255" type="VARCHAR" />
    <column name="is_correction" defaultValue="0" required="true" type="BOOLEAN" />
    <column name="disabled_engine" size="255" type="VARCHAR" />
    <foreign-key foreignTable="module" name="FK_TYPENOTIFICATION_MODULE0" onDelete="CASCADE" onUpdate="CASCADE">
      <reference foreign="unique_name" local="module_unique_name" />
    </foreign-key>
    <index name="FK_TYPENOTIFICATION_MODULE">
      <index-column name="module_unique_name" />
    </index>
  </table>
  <table name="module">
    <column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
    <column name="unique_name" required="true" size="255" type="VARCHAR" />
    <column name="label" primaryString="true" required="true" size="255" type="VARCHAR" />
    <column name="description" required="true" size="255" type="VARCHAR" />
  </table>
</database>
';
        $actual = "\n# This is a fix for InnoDB in MySQL >= 4.1.x\n# It \"suspends judgement\" for fkey relationships until are tables are set.\nSET FOREIGN_KEY_CHECKS = 0;\n\n-- ---------------------------------------------------------------------\n-- notification\n-- ---------------------------------------------------------------------\n\nDROP TABLE IF EXISTS `notification`;\n\nCREATE TABLE `notification`\n(\n    `id` INTEGER NOT NULL AUTO_INCREMENT,\n    `target_user_id` INTEGER NOT NULL,\n    `notification_type_unique_name` VARCHAR(255) NOT NULL,\n    `group_id` INTEGER,\n    `date` DATETIME NOT NULL,\n    `objects` TEXT,\n    `is_new` TINYINT(1) DEFAULT 1 NOT NULL,\n    PRIMARY KEY (`id`),\n    INDEX `FK_NOTIFICATION_TARGET_USER` (`target_user_id`),\n    INDEX `FK_NOTIFICATION_TYPENOTIFICATION` (`notification_type_unique_name`),\n    CONSTRAINT `FK_NOTIFICATION_TYPENOTIFICATION0`\n        FOREIGN KEY (`notification_type_unique_name`)\n        REFERENCES `notification_type` (`unique_name`)\n) ENGINE=InnoDb;\n\n-- ---------------------------------------------------------------------\n-- notification_type\n-- ---------------------------------------------------------------------\n\nDROP TABLE IF EXISTS `notification_type`;\n\nCREATE TABLE `notification_type`\n(\n    `module_unique_name` VARCHAR(255) NOT NULL,\n    `unique_name` VARCHAR(255) NOT NULL,\n    `is_correction` TINYINT(1) DEFAULT 0 NOT NULL,\n    `disabled_engine` VARCHAR(255),\n    PRIMARY KEY (`module_unique_name`,`unique_name`),\n    INDEX `FK_TYPENOTIFICATION_MODULE` (`module_unique_name`),\n    INDEX `I_referenced_FK_NOTIFICATION_TYPENOTIFICATION0_1` (`unique_name`),\n    CONSTRAINT `FK_TYPENOTIFICATION_MODULE0`\n        FOREIGN KEY (`module_unique_name`)\n        REFERENCES `module` (`unique_name`)\n        ON UPDATE CASCADE\n        ON DELETE CASCADE\n) ENGINE=InnoDb;\n\n-- ---------------------------------------------------------------------\n-- module\n-- ---------------------------------------------------------------------\n\nDROP TABLE IF EXISTS `module`;\n\nCREATE TABLE `module`\n(\n    `id` INTEGER NOT NULL AUTO_INCREMENT,\n    `unique_name` VARCHAR(255) NOT NULL,\n    `label` VARCHAR(255) NOT NULL,\n    `description` VARCHAR(255) NOT NULL,\n    PRIMARY KEY (`id`)\n) ENGINE=InnoDb;\n\n# This restores the fkey checks, after having unset them earlier\nSET FOREIGN_KEY_CHECKS = 1;\n";
        $platform = new MysqlPlatform();
        $platform->setDefaultTableEngine('InnoDb');
        $updatedBuilder = new PropelQuickBuilder();
        $updatedBuilder->setPlatform($platform);
        $updatedBuilder->setSchema($updatedSchema);
        $sql = $updatedBuilder->getSQL();
        $this->assertEquals($actual, $sql);
    }
 /**
  * Initializes db specific domain mapping.
  */
 protected function initialize()
 {
     parent::initialize();
     // HL -- commenting these out, as it turns out that while the date format is fixed
     // there is still a special meaning to TIMESTAMP in MySQL 4.1+
     // $this->setSchemaDomainMapping(new Domain(PropelTypes::TIMESTAMP, "TIMESTAMP"));
     // $this->setSchemaDomainMapping(new Domain(PropelTypes::BU_TIMESTAMP, "TIMESTAMP"));
 }
Example #5
0
 public function testUniqueTableName()
 {
     $platform = new MysqlPlatform();
     $config = new GeneratorConfig();
     $platform->setGeneratorConfig($config);
     $xmlToAppData = new XmlToAppData($platform, 'defaultpackage', null);
     try {
         $appData = $xmlToAppData->parseFile('fixtures/unique-column/table-schema.xml');
         $this->fail('Parsing file with duplicate table name throws exception');
     } catch (EngineException $e) {
         $this->assertTrue(true, 'Parsing file with duplicate table name throws exception');
     }
 }
    public function testGetAddTableDDLEngine()
    {
        $schema = <<<EOF
<database name="test">
    <table name="foo">
        <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
    </table>
</database>
EOF;
        $platform = new MysqlPlatform();
        $platform->setTableEngineKeyword('TYPE');
        $platform->setDefaultTableEngine('MEMORY');
        $xtad = new XmlToAppData($platform);
        $appData = $xtad->parseString($schema);
        $table = $appData->getDatabase()->getTable('foo');
        $expected = "\nCREATE TABLE `foo`\n(\n    `id` INTEGER NOT NULL AUTO_INCREMENT,\n    PRIMARY KEY (`id`)\n) TYPE=MEMORY;\n";
        $this->assertEquals($expected, $platform->getAddTableDDL($table));
    }
Example #7
0
 /**
  * @return Database
  */
 function getDatabaseSchema()
 {
     ClassLoader::import('DATABASE:propel:');
     ClassLoader::import('DATABASE:propel:model');
     ClassLoader::import('DATABASE:propel:reverse');
     ClassLoader::import('DATABASE:propel:reverse:mysql');
     ClassLoader::import('DATABASE:propel:platform');
     $parser = new MysqlSchemaParser($this);
     $database = new Database($this->getDBName());
     $platform = new MysqlPlatform($this);
     $platform->setDefaultTableEngine('InnoDB');
     $database->setPlatform($platform);
     $parser->parse($database);
     $database->doFinalInitialization();
     return $database;
 }
    public function testAddExtraIndicesForeignKeys()
    {
        $include_path = get_include_path();
        set_include_path($include_path . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../../../generator/lib'));
        $platform = new MysqlPlatform();
        $xmlToAppData = new XmlToAppData($platform);
        $config = new GeneratorConfig();
        $config->setBuildProperties(array('propel.behavior.autoaddpkbehavior.class' => 'behavior.AutoAddPkBehavior'));
        $xmlToAppData->setGeneratorConfig($config);
        $schema = <<<EOF
<database name="test1">

  <table name="foo">

    <behavior name="autoAddPKBehavior"/>
    <column name="name" type="VARCHAR"/>
    <column name="subid" type="INTEGER"/>

  </table>

  <table name="bar">

    <behavior name="autoAddPKBehavior"/>

    <column name="name" type="VARCHAR"/>
    <column name="subid" type="INTEGER"/>

    <foreign-key foreignTable="foo">
      <reference local="id" foreign="id"/>
      <reference local="subid" foreign="subid"/>
    </foreign-key>

  </table>
</database>
EOF;
        $expectedRelationSql = "\nCREATE TABLE `bar`\n(\n    `name` VARCHAR(255),\n    `subid` INTEGER,\n    `id` INTEGER NOT NULL AUTO_INCREMENT,\n    PRIMARY KEY (`id`),\n    INDEX `bar_FI_1` (`id`, `subid`)\n) ENGINE=MyISAM;\n";
        $appData = $xmlToAppData->parseString($schema);
        set_include_path($include_path);
        $table = $appData->getDatabase('test1')->getTable('bar');
        $relationTableSql = $platform->getAddTableDDL($table);
        $this->assertEquals($expectedRelationSql, $relationTableSql);
    }