Skip to content

Commit 7ac70a8

Browse files
author
SergeyGrishin
committed
--- add migrations ---
Fix some bugs in migrations functional
1 parent eb7a7e5 commit 7ac70a8

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/orm/DataBase/Table.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
34
namespace orm\DataBase;
45

56

@@ -45,10 +46,10 @@ public function migrate()
4546
{
4647
try {
4748
(new QueryExecutor(PdoAdapter::getInstance()
48-
->getPdoObject()->prepare(
49-
(new Migration($this->table_fields, $this->table_name))
50-
->buildMigrationSqlCode()), []))
51-
->execute();
49+
->getPdoObject()->prepare(
50+
(new Migration($this->table_fields, $this->table_name))
51+
->buildMigrationSqlCode()), []))
52+
->executeSql();
5253
} catch (\PDOException $e) {
5354
throw new MigrationException($e->getMessage());
5455
}

lib/orm/Query/QueryExecutor.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,19 @@ public function select()
9696
* select|insertOrUpdate|delete). Substitute data to prepared query
9797
* and execute it.
9898
*/
99-
public function execute()
99+
private function execute()
100100
{
101101
$this->pdo->beginTransaction();
102102
$this->query->execute($this->data);
103103
}
104104

105+
/**
106+
* Execute pure sql query. Use this only for migrations.
107+
*/
108+
public function executeSql()
109+
{
110+
$this->execute();
111+
$this->pdo->commit();
112+
}
113+
105114
}

0 commit comments

Comments
 (0)