src/Schema/Service/SqlService.php
public function restore()
    {
        //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($data['name'])) {
            throw Exception::forSchemaAlreadyExists($data['name']);
        }

        //if there's no system
        if (!$this->exists('_' . $data['name'])) {
            //go to create mode
            return $this->create($data, true);
        }

        $queries[] = 'RENAME TABLE `_' . $data['name'] . '` TO `' . $data['name'] . '`;';

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

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

        return $results;
    }
public function restore()
    {
        //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($data['name'])) {
            throw Exception::forSchemaAlreadyExists($data['name']);
        }

        //if there's no system
        if (!$this->exists('_' . $data['name'])) {
            //go to create mode
            return $this->create($data, true);
        }

        $queries[] = 'RENAME TABLE `_' . $data['name'] . '` TO `' . $data['name'] . '`;';

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

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

        return $results;
    }
public function restore ( ) { //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 ( $ data [ 'name' ] ) ) { throw Exception :: forSchemaAlreadyExists ( $ data [ 'name' ] ) ; } //if there's no system if ( ! $ this -> exists ( '_' . $ data [ 'name' ] ) ) { //go to create mode return $ this -> create ( $ data , true ) ; } $ queries [ ] = 'RENAME TABLE `_' . $ data [ 'name' ] . '` TO `' . $ data [ 'name' ] . '`;' ; //determine the relation schema foreach ( $ data [ 'relations' ] as $ table => $ relation ) { $ queries [ ] = 'RENAME TABLE `_' . $ table . '` TO `' . $ table . '`;' ; } //execute queries $ results = [ ] ; foreach ( $ queries as $ query ) { $ results [ ] = [ 'query' => $ query , 'results' => $ this -> resource -> query ( $ query ) ] ; } return $ results ; }
Restores a table

@param array $data

@return array
Restores a table