Permalink
Browse files

Modyllic_Index_Foreign -> Modyllic_Schema_Index_Foreign

  • Loading branch information...
1 parent df3a8a0 commit cb36f40ba14762f5de523c0d149ba57633ed58e1 @iarna committed Apr 24, 2012
@@ -43,7 +43,7 @@ function column_aliases( $column ) {
}
}
function foreign_key($index) {
- if ( $index->weak != Modyllic_Index_Foreign::WEAK_DEFAULT ) {
+ if ( $index->weak != Modyllic_Schema_Index_Foreign::WEAK_DEFAULT ) {
$this->add( " WEAKLY REFERENCES %id", $index->references['table'] );
}
else {
@@ -629,8 +629,8 @@ function create_column( $column ) {
}
function index_meta($index) {
- if ( $index instanceOf Modyllic_Index_Foreign ) {
- if ( $index->weak != Modyllic_Index_Foreign::WEAK_DEFAULT ) {
+ if ( $index instanceOf Modyllic_Schema_Index_Foreign ) {
+ if ( $index->weak != Modyllic_Schema_Index_Foreign::WEAK_DEFAULT ) {
return array( "weak" => $index->weak );
}
else {
@@ -648,7 +648,7 @@ function add_index( $index ) {
}
function drop_index( $index ) {
- if ( $index instanceOf Modyllic_Index_Foreign ) {
+ if ( $index instanceOf Modyllic_Schema_Index_Foreign ) {
$this->extend("DROP FOREIGN KEY %id", $index->cname);
}
else if ( $index->primary ) {
@@ -665,7 +665,7 @@ function drop_index( $index ) {
}
function ignore_index( $index ) {
- if ( $index instanceOf Modyllic_Index_Foreign and $index->weak ) {
+ if ( $index instanceOf Modyllic_Schema_Index_Foreign and $index->weak ) {
return true;
}
else {
@@ -681,7 +681,7 @@ function create_index( $index, $prefix=null ) {
$this->partial($prefix);
}
$this->extend();
- if ( $index instanceOf Modyllic_Index_Foreign ) {
+ if ( $index instanceOf Modyllic_Schema_Index_Foreign ) {
if ( ! $index->dynamic_name and $index->cname ) {
$this->add( "CONSTRAINT %id ", $index->cname );
}
@@ -717,7 +717,7 @@ function create_index( $index, $prefix=null ) {
}
}
$this->add( ")" );
- if ( $index instanceOf Modyllic_Index_Foreign ) {
+ if ( $index instanceOf Modyllic_Schema_Index_Foreign ) {
$this->foreign_key( $index );
}
if ( isset($index->using) ) {
View
@@ -858,7 +858,7 @@ function cmd_CREATE_TABLE() {
}
}
foreach ($this->ctx->indexes as &$index) {
- if ($index instanceOf Modyllic_Index_Foreign ) {
+ if ($index instanceOf Modyllic_Schema_Index_Foreign ) {
$this->add_foreign_key_index( '', $index );
}
}
@@ -979,7 +979,7 @@ function load_column() {
$column->aliases += $this->get_array();
}
else if ( $this->cur()->token() == 'REFERENCES' ) {
- $key = new Modyllic_Index_Foreign();
+ $key = new Modyllic_Schema_Index_Foreign();
if ( $this->peek_next()->token() == 'WEAKLY' ) {
$this->get_reserved();
$key->weak = true;
@@ -1093,7 +1093,7 @@ function load_regular_key($token) {
}
function load_foreign_key($token) {
- $key = new Modyllic_Index_Foreign();
+ $key = new Modyllic_Schema_Index_Foreign();
if ( $token == 'CONSTRAINT' ) {
$key->cname = $this->get_ident();
$token = $this->get_reserved();
@@ -1212,7 +1212,7 @@ function add_foreign_key_index( $name, $key ) {
// Scan to see if another key would meet our needs
$matched = false;
foreach ( $this->ctx->indexes as &$other_key ) {
- if ( $other_key instanceOf Modyllic_Index_Foreign ) { continue; }
+ if ( $other_key instanceOf Modyllic_Schema_Index_Foreign ) { continue; }
if ( count($key->columns) <= count($other_key->columns) ) {
$matched = true;
foreach ( $key->columns as $idx=>&$colname ) {
View
@@ -9,6 +9,10 @@
require_once "Modyllic/SQL.php";
require_once "Modyllic/Types.php";
+// Components
+require_once "Modyllic/Schema/Index.php";
+require_once "Modyllic/Schema/Index/Foreign.php";
+
/**
* A base class for various schema objects. Handles generic things like
* providing previous values for the diff engine. In a perfect world this
@@ -266,7 +270,7 @@ function add_column($column) {
return $column;
}
/**
- * @param Modyllic_Index $index
+ * @param Modyllic_Schema_Index $index
*/
function add_index($index) {
$name = $index->get_name();
@@ -428,35 +432,6 @@ function equal_to($other) {
}
}
-
-class Modyllic_Index_Foreign extends Modyllic_Index {
- public $cname = "";
- const WEAK_DEFAULT = false;
- public $weak = self::WEAK_DEFAULT;
- public $references = array();
- /**
- * @param string $name
- */
- function __construct($name="") {
- parent::__construct($name);
- $this->references['table'] = "";
- $this->references['columns'] = array();
- $this->references['on_delete'] = "";
- $this->references['on_update'] = "";
- }
-
- function get_name() {
- return "~".$this->cname;
- }
-
- function equal_to($other) {
- if ( ! parent::equal_to($other) ) { return false; }
- if ( $this->references != $other->references ) { return false; }
- if ( $this->weak != $other->weak ) { return false; }
- return true;
- }
-}
-
class Modyllic_CodeBody extends Modyllic_Diffable {
public $body = "BEGIN\nEND";
/**
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Copyright © 2012 Online Buddies, Inc. - All Rights Reserved
+ *
+ * @package Modyllic
+ * @author bturner@online-buddies.com
+ */
+
+class Modyllic_Schema_Index_Foreign extends Modyllic_Schema_Index {
+ public $cname = "";
+ const WEAK_DEFAULT = false;
+ public $weak = self::WEAK_DEFAULT;
+ public $references = array();
+ /**
+ * @param string $name
+ */
+ function __construct($name="") {
+ parent::__construct($name);
+ $this->references['table'] = "";
+ $this->references['columns'] = array();
+ $this->references['on_delete'] = "";
+ $this->references['on_update'] = "";
+ }
+
+ function get_name() {
+ return "~".$this->cname;
+ }
+
+ function equal_to($other) {
+ if ( ! parent::equal_to($other) ) { return false; }
+ if ( $this->references != $other->references ) { return false; }
+ if ( $this->weak != $other->weak ) { return false; }
+ return true;
+ }
+}

0 comments on commit cb36f40

Please sign in to comment.