Skip to content

Commit

Permalink
Modyllic_Column -> Modyllic_Schema_Column
Browse files Browse the repository at this point in the history
  • Loading branch information
iarna committed Apr 24, 2012
1 parent cb36f40 commit 9092f2b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 46 deletions.
6 changes: 3 additions & 3 deletions Modyllic/Diff.php
Expand Up @@ -569,23 +569,23 @@ function __construct($name) {

/**
* Note that a column was added
* @param Modyllic_Column $column
* @param Modyllic_Schema_Column $column
*/
function add_column($column) {
$this->add['columns'][$column->name] = $column;
}

/**
* Note that a column was removed
* @param Modyllic_Column $column
* @param Modyllic_Schema_Column $column
*/
function remove_column($column) {
$this->remove['columns'][$column->name] = $column;
}

/**
* Note that a column was updated
* @param Modyllic_Column $column
* @param Modyllic_Schema_Column $column
*/
function update_column($column) {
$this->update['columns'][$column->name] = $column;
Expand Down
2 changes: 1 addition & 1 deletion Modyllic/Parser.php
Expand Up @@ -914,7 +914,7 @@ function maybe_table_option() {
function load_column() {
// ident type [NOT NULL|NULL] [DEFAULT value] [ON UPDATE token] [AUTO_INCREMENT]
// [PRIMARY KEY] [COMMENT string] [ALIASES (token,...)]
$column = $this->ctx->add_column(new Modyllic_Column( $this->assert_ident() ));
$column = $this->ctx->add_column(new Modyllic_Schema_Column( $this->assert_ident() ));
$column->type = $this->get_type();

$is_unique = false;
Expand Down
43 changes: 2 additions & 41 deletions Modyllic/Schema.php
Expand Up @@ -12,6 +12,7 @@
// Components
require_once "Modyllic/Schema/Index.php";
require_once "Modyllic/Schema/Index/Foreign.php";
require_once "Modyllic/Schema/Column.php";

/**
* A base class for various schema objects. Handles generic things like
Expand Down Expand Up @@ -259,7 +260,7 @@ function __construct($name) {


/**
* @param Modyllic_Column $column
* @param Modyllic_Schema_Column $column
*/
function add_column($column) {
if ( isset($this->last_column) ) {
Expand Down Expand Up @@ -392,46 +393,6 @@ function match_row($row) {

}

/**
* A collection of attributes describing a column in a table
*/
class Modyllic_Column extends Modyllic_Diffable {
public $name;
public $aliases = array();
public $previously;
public $type;
public $null = true;
public $default = "NULL";
public $auto_increment = false;
public $on_update;
public $docs = "";
public $after;
public $is_primary;

/**
* @param string $name
*/
function __construct($name) {
$this->name = $name;
}


/**
* @param Modyllic_Column $other
* @returns bool True if $other is equivalent to $this
*/
function equal_to($other) {
if ( $this->name != $other->name ) { return false; }
if ( ! $this->type->equal_to( $other->type ) ) { return false; }
if ( $this->null != $other->null ) { return false; }
if ( $this->default != $other->default ) { return false; }
if ( $this->auto_increment != $other->auto_increment ) { return false; }
if ( $this->on_update != $other->on_update ) { return false; }
if ( $this->aliases != $other->aliases ) { return false; }
return true;
}
}

class Modyllic_CodeBody extends Modyllic_Diffable {
public $body = "BEGIN\nEND";
/**
Expand Down
48 changes: 48 additions & 0 deletions Modyllic/Schema/Column.php
@@ -0,0 +1,48 @@
<?php
/**
* Copyright © 2012 Online Buddies, Inc. - All Rights Reserved
*
* @package Modyllic
* @author bturner@online-buddies.com
*/

/**
* A collection of attributes describing a column in a table
*/
class Modyllic_Schema_Column extends Modyllic_Diffable {
public $name;
public $aliases = array();
public $previously;
public $type;
public $null = true;
public $default = "NULL";
public $auto_increment = false;
public $on_update;
public $docs = "";
public $after;
public $is_primary;

/**
* @param string $name
*/
function __construct($name) {
$this->name = $name;
}


/**
* @param Modyllic_Schema_Column $other
* @returns bool True if $other is equivalent to $this
*/
function equal_to($other) {
if ( $this->name != $other->name ) { return false; }
if ( ! $this->type->equal_to( $other->type ) ) { return false; }
if ( $this->null != $other->null ) { return false; }
if ( $this->default != $other->default ) { return false; }
if ( $this->auto_increment != $other->auto_increment ) { return false; }
if ( $this->on_update != $other->on_update ) { return false; }
if ( $this->aliases != $other->aliases ) { return false; }
return true;
}
}

2 changes: 1 addition & 1 deletion test/General_Functional.t
Expand Up @@ -37,7 +37,7 @@ is( $test_table->charset, "utf8", "The default charset got set" );
is( count($test_table->columns), 1, "One column found" );
is( count($test_table->indexes), 0, "No indexes found" );
$column = $test_table->columns['id'];
ok( $column instanceOf Modyllic_Column, "Column id isa Modyllic_Column" );
ok( $column instanceOf Modyllic_Schema_Column, "Column id isa Modyllic_Schema_Column" );
is( $column->name, "id", "Column name set" );
is( count($column->aliases), 0, "No aliases" );
ok( $column->type instanceOf Modyllic_Integer, "Column type set" );
Expand Down

0 comments on commit 9092f2b

Please sign in to comment.