1 | <?php namespace Nwidart\DbExporter; |
||
5 | abstract class DbExporter |
||
6 | { |
||
7 | /** |
||
8 | * Contains the ignore tables |
||
9 | * @var array $ignore |
||
10 | */ |
||
11 | public static $ignore = array('migrations'); |
||
12 | public static $remote; |
||
13 | |||
14 | /** |
||
15 | * Get all the tables |
||
16 | * @return mixed |
||
17 | */ |
||
18 | protected function getTables() |
||
19 | { |
||
20 | $pdo = DB::connection()->getPdo(); |
||
21 | return $pdo->query('SELECT table_name FROM information_schema.tables WHERE table_schema="' . $this->database . '"'); |
||
22 | } |
||
23 | |||
24 | public function getTableIndexes($table) |
||
25 | { |
||
26 | $pdo = DB::connection()->getPdo(); |
||
27 | return $pdo->query('SHOW INDEX FROM ' . $table . ' WHERE Key_name != "PRIMARY"'); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Get all the columns for a given table |
||
32 | * @param $table |
||
33 | * @return mixed |
||
34 | */ |
||
35 | protected function getTableDescribes($table) |
||
36 | { |
||
37 | return DB::table('information_schema.columns') |
||
38 | ->where('table_schema', '=', $this->database) |
||
39 | ->where('table_name', '=', $table) |
||
40 | ->get($this->selects); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Grab all the table data |
||
45 | * @param $table |
||
46 | * @return mixed |
||
47 | */ |
||
48 | protected function getTableData($table) |
||
52 | |||
53 | /** |
||
54 | * Write the file |
||
55 | * @return mixed |
||
56 | */ |
||
57 | abstract public function write(); |
||
58 | |||
59 | /** |
||
60 | * Convert the database to a usefull format |
||
61 | * @param null $database |
||
62 | * @return mixed |
||
63 | */ |
||
64 | abstract public function convert($database = null); |
||
65 | |||
66 | /** |
||
67 | * Put the converted stub into a template |
||
68 | * @return mixed |
||
69 | */ |
||
70 | abstract protected function compile(); |
||
71 | } |