src/Schema/Service/SqlService.php
public function remove($restorable = true)
    {
        //translate model data to sql data
        if (is_null($this->schema)) {
            throw Exception::forNoSchema();
        }

        $data = $this->schema->toSql();

        //queries to run
        $queries = [];

        // check if table is already archived
        if ($this->exists(sprintf('_%s', $data['name']))) {
            throw Exception::forSchemaArchiveExists($data['name']);
        }

        //if system exists
        if ($this->exists($data['name'])) {
            if ($restorable) {
                $queries[] = 'RENAME TABLE `' . $data['name'] . '` TO `_' . $data['name'] . '`;';

                //determine the relation schema
                foreach ($data['relations'] as $table => $relation) {
                    $queries[] = 'RENAME TABLE `' . $table . '` TO `_' . $table . '`;';
                }
            } else {
                $queries[] = 'DROP TABLE IF EXISTS `' . $data['name'] . '`;';
                $queries[] = 'DROP TABLE IF EXISTS `_' . $data['name'] . '`;';

                //determine the relation schema
                foreach ($data['relations'] as $table => $relation) {
                    $queries[] = 'DROP TABLE IF EXISTS `'. $table . '`;';
                    $queries[] = 'DROP TABLE IF EXISTS `_'. $table . '`;';
                }
            }
        }

        //execute queries
        $results = [];
        foreach ($queries as $query) {
            $results[] = [
                'query' => $query,
                'results' => $this->resource->query($query)
            ];
        }

        return $results;
    }
public function remove($restorable = true)
    {
        //translate model data to sql data
        if (is_null($this->schema)) {
            throw Exception::forNoSchema();
        }

        $data = $this->schema->toSql();

        //queries to run
        $queries = [];

        // check if table is already archived
        if ($this->exists(sprintf('_%s', $data['name']))) {
            throw Exception::forSchemaArchiveExists($data['name']);
        }

        //if system exists
        if ($this->exists($data['name'])) {
            if ($restorable) {
                $queries[] = 'RENAME TABLE `' . $data['name'] . '` TO `_' . $data['name'] . '`;';

                //determine the relation schema
                foreach ($data['relations'] as $table => $relation) {
                    $queries[] = 'RENAME TABLE `' . $table . '` TO `_' . $table . '`;';
                }
            } else {
                $queries[] = 'DROP TABLE IF EXISTS `' . $data['name'] . '`;';
                $queries[] = 'DROP TABLE IF EXISTS `_' . $data['name'] . '`;';

                //determine the relation schema
                foreach ($data['relations'] as $table => $relation) {
                    $queries[] = 'DROP TABLE IF EXISTS `'. $table . '`;';
                    $queries[] = 'DROP TABLE IF EXISTS `_'. $table . '`;';
                }
            }
        }

        //execute queries
        $results = [];
        foreach ($queries as $query) {
            $results[] = [
                'query' => $query,
                'results' => $this->resource->query($query)
            ];
        }

        return $results;
    }
public function remove ( $ restorable = true ) { //translate model data to sql data if ( is_null ( $ this -> schema ) ) { throw Exception :: forNoSchema ( ) ; } $ data = $ this -> schema -> toSql ( ) ; //queries to run $ queries = [ ] ; // check if table is already archived if ( $ this -> exists ( sprintf ( '_%s' , $ data [ 'name' ] ) ) ) { throw Exception :: forSchemaArchiveExists ( $ data [ 'name' ] ) ; } //if system exists if ( $ this -> exists ( $ data [ 'name' ] ) ) { if ( $ restorable ) { $ queries [ ] = 'RENAME TABLE `' . $ data [ 'name' ] . '` TO `_' . $ data [ 'name' ] . '`;' ; //determine the relation schema foreach ( $ data [ 'relations' ] as $ table => $ relation ) { $ queries [ ] = 'RENAME TABLE `' . $ table . '` TO `_' . $ table . '`;' ; } } else { $ queries [ ] = 'DROP TABLE IF EXISTS `' . $ data [ 'name' ] . '`;' ; $ queries [ ] = 'DROP TABLE IF EXISTS `_' . $ data [ 'name' ] . '`;' ; //determine the relation schema foreach ( $ data [ 'relations' ] as $ table => $ relation ) { $ queries [ ] = 'DROP TABLE IF EXISTS `' . $ table . '`;' ; $ queries [ ] = 'DROP TABLE IF EXISTS `_' . $ table . '`;' ; } } } //execute queries $ results = [ ] ; foreach ( $ queries as $ query ) { $ results [ ] = [ 'query' => $ query , 'results' => $ this -> resource -> query ( $ query ) ] ; } return $ results ; }
Removes a table

@param array $data

@return array
Removes a table