1+ <?php
2+
3+ namespace TapestryCloud \Database ;
4+
5+ use Doctrine \DBAL \Connection ;
6+
7+ class Migrator
8+ {
9+
10+ /**
11+ * @var Connection
12+ */
13+ private $ connection ;
14+
15+ /**
16+ * @var array
17+ */
18+ private $ migrations = [
19+ 'CREATE TABLE IF NOT EXISTS content_types ( ' .
20+ 'id INTEGER PRIMARY KEY, ' .
21+ 'name TEXT NOT NULL, ' .
22+ 'path TEXT NOT NULL, ' .
23+ 'template TEXT NOT NULL, ' .
24+ 'permalink TEXT NOT NULL, ' .
25+ 'enabled INTEGER NOT NULL DEFAULT 0 ' .
26+ ') ' ,
27+ 'CREATE TABLE IF NOT EXISTS files ( ' .
28+ 'id INTEGER PRIMARY KEY, ' .
29+ 'uid TEXT NOT NULL ' .
30+ ') ' ,
31+ 'CREATE TABLE IF NOT EXISTS taxonomies ( ' .
32+ 'id INTEGER PRIMARY KEY, ' .
33+ 'name TEXT NOT NULL ' .
34+ ') ' ,
35+ 'CREATE TABLE IF NOT EXISTS content_type_taxonomies ( ' .
36+ 'id INTEGER PRIMARY KEY, ' .
37+ 'content_type_id INTEGER NOT NULL, ' .
38+ 'taxonomy_id INTEGER NOT NULL, ' .
39+ 'FOREIGN KEY (content_type_id) ' .
40+ 'REFERENCES content_types(content_type_id) ON UPDATE CASCADE ON DELETE CASCADE, ' .
41+ 'FOREIGN KEY (taxonomy_id) ' .
42+ 'REFERENCES taxonomies(taxonomy_id) ON UPDATE CASCADE ON DELETE CASCADE ' .
43+ ') ' ,
44+ 'CREATE TABLE IF NOT EXISTS taxonomy_classifications ( ' .
45+ 'id INTEGER PRIMARY KEY, ' .
46+ 'taxonomy_id INTEGER NOT NULL, ' .
47+ 'name TEXT NOT NULL, ' .
48+ 'FOREIGN KEY (taxonomy_id) ' .
49+ 'REFERENCES taxonomies(taxonomy_id) ON UPDATE CASCADE ON DELETE CASCADE ' .
50+ ') ' ,
51+ 'CREATE TABLE IF NOT EXISTS taxonomy_classification_file ( ' .
52+ 'id INTEGER PRIMARY KEY, ' .
53+ 'taxonomy_classification_id INTEGER NOT NULL, ' .
54+ 'file_id INTEGER NOT NULL, ' .
55+ 'FOREIGN KEY (taxonomy_classification_id) ' .
56+ 'REFERENCES taxonomy_classifications(taxonomy_classification_id) ON UPDATE CASCADE ON DELETE CASCADE, ' .
57+ 'FOREIGN KEY (file_id) ' .
58+ 'REFERENCES files(file_id) ON UPDATE CASCADE ON DELETE CASCADE ' .
59+ ') ' ,
60+ ];
61+
62+ /**
63+ * Exporter constructor.
64+ * @param Connection $connection
65+ * @throws \Exception
66+ */
67+ public function __construct (Connection $ connection )
68+ {
69+ $ this ->connection = $ connection ;
70+ }
71+
72+ public function migrate ()
73+ {
74+ foreach ($ this ->migrations as $ migration ) {
75+ $ this ->connection ->exec ($ migration );
76+ }
77+ }
78+ }
0 commit comments