@@ -23,7 +23,6 @@ |
||
23 | 23 | |
24 | 24 | namespace OC\DB; |
25 | 25 | |
26 | -use Doctrine\DBAL\DBALException; |
|
27 | 26 | use Doctrine\DBAL\Schema\Schema; |
28 | 27 | use OCP\DB\ISchemaWrapper; |
29 | 28 | use OCP\IDBConnection; |
@@ -30,107 +30,107 @@ |
||
30 | 30 | |
31 | 31 | class SchemaWrapper implements ISchemaWrapper { |
32 | 32 | |
33 | - /** @var IDBConnection|Connection */ |
|
34 | - protected $connection; |
|
35 | - |
|
36 | - /** @var Schema */ |
|
37 | - protected $schema; |
|
38 | - |
|
39 | - /** @var array */ |
|
40 | - protected $tablesToDelete = []; |
|
41 | - |
|
42 | - /** |
|
43 | - * @param IDBConnection $connection |
|
44 | - */ |
|
45 | - public function __construct(IDBConnection $connection) { |
|
46 | - $this->connection = $connection; |
|
47 | - $this->schema = $this->connection->createSchema(); |
|
48 | - } |
|
49 | - |
|
50 | - public function getWrappedSchema() { |
|
51 | - return $this->schema; |
|
52 | - } |
|
53 | - |
|
54 | - public function performDropTableCalls() { |
|
55 | - foreach ($this->tablesToDelete as $tableName => $true) { |
|
56 | - $this->connection->dropTable($tableName); |
|
57 | - unset($this->tablesToDelete[$tableName]); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Gets all table names |
|
63 | - * |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function getTableNamesWithoutPrefix() { |
|
67 | - $tableNames = $this->schema->getTableNames(); |
|
68 | - return array_map(function($tableName) { |
|
69 | - if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
|
70 | - return substr($tableName, strlen($this->connection->getPrefix())); |
|
71 | - } |
|
72 | - |
|
73 | - return $tableName; |
|
74 | - }, $tableNames); |
|
75 | - } |
|
76 | - |
|
77 | - // Overwritten methods |
|
78 | - |
|
79 | - /** |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public function getTableNames() { |
|
83 | - return $this->schema->getTableNames(); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param string $tableName |
|
88 | - * |
|
89 | - * @return \Doctrine\DBAL\Schema\Table |
|
90 | - * @throws \Doctrine\DBAL\Schema\SchemaException |
|
91 | - */ |
|
92 | - public function getTable($tableName) { |
|
93 | - return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Does this schema have a table with the given name? |
|
98 | - * |
|
99 | - * @param string $tableName |
|
100 | - * |
|
101 | - * @return boolean |
|
102 | - */ |
|
103 | - public function hasTable($tableName) { |
|
104 | - return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Creates a new table. |
|
109 | - * |
|
110 | - * @param string $tableName |
|
111 | - * @return \Doctrine\DBAL\Schema\Table |
|
112 | - */ |
|
113 | - public function createTable($tableName) { |
|
114 | - return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Drops a table from the schema. |
|
119 | - * |
|
120 | - * @param string $tableName |
|
121 | - * @return \Doctrine\DBAL\Schema\Schema |
|
122 | - */ |
|
123 | - public function dropTable($tableName) { |
|
124 | - $this->tablesToDelete[$tableName] = true; |
|
125 | - return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Gets all tables of this schema. |
|
130 | - * |
|
131 | - * @return \Doctrine\DBAL\Schema\Table[] |
|
132 | - */ |
|
133 | - public function getTables() { |
|
134 | - return $this->schema->getTables(); |
|
135 | - } |
|
33 | + /** @var IDBConnection|Connection */ |
|
34 | + protected $connection; |
|
35 | + |
|
36 | + /** @var Schema */ |
|
37 | + protected $schema; |
|
38 | + |
|
39 | + /** @var array */ |
|
40 | + protected $tablesToDelete = []; |
|
41 | + |
|
42 | + /** |
|
43 | + * @param IDBConnection $connection |
|
44 | + */ |
|
45 | + public function __construct(IDBConnection $connection) { |
|
46 | + $this->connection = $connection; |
|
47 | + $this->schema = $this->connection->createSchema(); |
|
48 | + } |
|
49 | + |
|
50 | + public function getWrappedSchema() { |
|
51 | + return $this->schema; |
|
52 | + } |
|
53 | + |
|
54 | + public function performDropTableCalls() { |
|
55 | + foreach ($this->tablesToDelete as $tableName => $true) { |
|
56 | + $this->connection->dropTable($tableName); |
|
57 | + unset($this->tablesToDelete[$tableName]); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Gets all table names |
|
63 | + * |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function getTableNamesWithoutPrefix() { |
|
67 | + $tableNames = $this->schema->getTableNames(); |
|
68 | + return array_map(function($tableName) { |
|
69 | + if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
|
70 | + return substr($tableName, strlen($this->connection->getPrefix())); |
|
71 | + } |
|
72 | + |
|
73 | + return $tableName; |
|
74 | + }, $tableNames); |
|
75 | + } |
|
76 | + |
|
77 | + // Overwritten methods |
|
78 | + |
|
79 | + /** |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public function getTableNames() { |
|
83 | + return $this->schema->getTableNames(); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param string $tableName |
|
88 | + * |
|
89 | + * @return \Doctrine\DBAL\Schema\Table |
|
90 | + * @throws \Doctrine\DBAL\Schema\SchemaException |
|
91 | + */ |
|
92 | + public function getTable($tableName) { |
|
93 | + return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Does this schema have a table with the given name? |
|
98 | + * |
|
99 | + * @param string $tableName |
|
100 | + * |
|
101 | + * @return boolean |
|
102 | + */ |
|
103 | + public function hasTable($tableName) { |
|
104 | + return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Creates a new table. |
|
109 | + * |
|
110 | + * @param string $tableName |
|
111 | + * @return \Doctrine\DBAL\Schema\Table |
|
112 | + */ |
|
113 | + public function createTable($tableName) { |
|
114 | + return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Drops a table from the schema. |
|
119 | + * |
|
120 | + * @param string $tableName |
|
121 | + * @return \Doctrine\DBAL\Schema\Schema |
|
122 | + */ |
|
123 | + public function dropTable($tableName) { |
|
124 | + $this->tablesToDelete[$tableName] = true; |
|
125 | + return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Gets all tables of this schema. |
|
130 | + * |
|
131 | + * @return \Doctrine\DBAL\Schema\Table[] |
|
132 | + */ |
|
133 | + public function getTables() { |
|
134 | + return $this->schema->getTables(); |
|
135 | + } |
|
136 | 136 | } |
@@ -36,170 +36,170 @@ |
||
36 | 36 | |
37 | 37 | class GenerateFromSchemaFileCommand extends GenerateCommand { |
38 | 38 | |
39 | - /** @var IConfig */ |
|
40 | - protected $config; |
|
39 | + /** @var IConfig */ |
|
40 | + protected $config; |
|
41 | 41 | |
42 | - /** @var IAppManager */ |
|
43 | - protected $appManager; |
|
42 | + /** @var IAppManager */ |
|
43 | + protected $appManager; |
|
44 | 44 | |
45 | - public function __construct(IConfig $config, IAppManager $appManager, IDBConnection $connection) { |
|
46 | - parent::__construct($connection); |
|
47 | - $this->config = $config; |
|
48 | - $this->appManager = $appManager; |
|
49 | - } |
|
45 | + public function __construct(IConfig $config, IAppManager $appManager, IDBConnection $connection) { |
|
46 | + parent::__construct($connection); |
|
47 | + $this->config = $config; |
|
48 | + $this->appManager = $appManager; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - protected function configure() { |
|
53 | - parent::configure(); |
|
52 | + protected function configure() { |
|
53 | + parent::configure(); |
|
54 | 54 | |
55 | - $this->setName('migrations:generate-from-schema'); |
|
56 | - } |
|
55 | + $this->setName('migrations:generate-from-schema'); |
|
56 | + } |
|
57 | 57 | |
58 | - public function execute(InputInterface $input, OutputInterface $output) { |
|
59 | - $appName = $input->getArgument('app'); |
|
60 | - $version = $input->getArgument('version'); |
|
58 | + public function execute(InputInterface $input, OutputInterface $output) { |
|
59 | + $appName = $input->getArgument('app'); |
|
60 | + $version = $input->getArgument('version'); |
|
61 | 61 | |
62 | - if (!preg_match('/^\d{1,16}$/',$version)) { |
|
63 | - $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>'); |
|
64 | - return 1; |
|
65 | - } |
|
62 | + if (!preg_match('/^\d{1,16}$/',$version)) { |
|
63 | + $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>'); |
|
64 | + return 1; |
|
65 | + } |
|
66 | 66 | |
67 | - $schemaFile = $this->appManager->getAppPath($appName) . '/appinfo/database.xml'; |
|
68 | - if (!file_exists($schemaFile)) { |
|
69 | - $output->writeln('<error>App ' . $appName . ' does not have a database.xml file</error>'); |
|
70 | - return 2; |
|
71 | - } |
|
67 | + $schemaFile = $this->appManager->getAppPath($appName) . '/appinfo/database.xml'; |
|
68 | + if (!file_exists($schemaFile)) { |
|
69 | + $output->writeln('<error>App ' . $appName . ' does not have a database.xml file</error>'); |
|
70 | + return 2; |
|
71 | + } |
|
72 | 72 | |
73 | - $reader = new MDB2SchemaReader($this->config, $this->connection->getDatabasePlatform()); |
|
74 | - $schema = new Schema(); |
|
75 | - $reader->loadSchemaFromFile($schemaFile, $schema); |
|
73 | + $reader = new MDB2SchemaReader($this->config, $this->connection->getDatabasePlatform()); |
|
74 | + $schema = new Schema(); |
|
75 | + $reader->loadSchemaFromFile($schemaFile, $schema); |
|
76 | 76 | |
77 | - $schemaBody = $this->schemaToMigration($schema); |
|
77 | + $schemaBody = $this->schemaToMigration($schema); |
|
78 | 78 | |
79 | - $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); |
|
79 | + $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); |
|
80 | 80 | |
81 | - $date = date('YmdHis'); |
|
82 | - $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date, $schemaBody); |
|
81 | + $date = date('YmdHis'); |
|
82 | + $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date, $schemaBody); |
|
83 | 83 | |
84 | - $output->writeln("New migration class has been generated to <info>$path</info>"); |
|
85 | - return 0; |
|
86 | - } |
|
84 | + $output->writeln("New migration class has been generated to <info>$path</info>"); |
|
85 | + return 0; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @param Schema $schema |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - protected function schemaToMigration(Schema $schema) { |
|
93 | - $content = <<<'EOT' |
|
88 | + /** |
|
89 | + * @param Schema $schema |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + protected function schemaToMigration(Schema $schema) { |
|
93 | + $content = <<<'EOT' |
|
94 | 94 | /** @var ISchemaWrapper $schema */ |
95 | 95 | $schema = $schemaClosure(); |
96 | 96 | |
97 | 97 | EOT; |
98 | 98 | |
99 | - foreach ($schema->getTables() as $table) { |
|
100 | - $content .= str_replace('{{table-name}}', substr($table->getName(), 3), <<<'EOT' |
|
99 | + foreach ($schema->getTables() as $table) { |
|
100 | + $content .= str_replace('{{table-name}}', substr($table->getName(), 3), <<<'EOT' |
|
101 | 101 | |
102 | 102 | if (!$schema->hasTable('{{table-name}}')) { |
103 | 103 | $table = $schema->createTable('{{table-name}}'); |
104 | 104 | |
105 | 105 | EOT |
106 | - ); |
|
106 | + ); |
|
107 | 107 | |
108 | - foreach ($table->getColumns() as $column) { |
|
109 | - $content .= str_replace(['{{name}}', '{{type}}'], [$column->getName(), $column->getType()->getName()], <<<'EOT' |
|
108 | + foreach ($table->getColumns() as $column) { |
|
109 | + $content .= str_replace(['{{name}}', '{{type}}'], [$column->getName(), $column->getType()->getName()], <<<'EOT' |
|
110 | 110 | $table->addColumn('{{name}}', '{{type}}', [ |
111 | 111 | |
112 | 112 | EOT |
113 | - ); |
|
114 | - if ($column->getAutoincrement()) { |
|
115 | - $content .= <<<'EOT' |
|
113 | + ); |
|
114 | + if ($column->getAutoincrement()) { |
|
115 | + $content .= <<<'EOT' |
|
116 | 116 | 'autoincrement' => true, |
117 | 117 | |
118 | 118 | EOT; |
119 | - } |
|
120 | - $content .= str_replace('{{notnull}}', $column->getNotnull() ? 'true' : 'false', <<<'EOT' |
|
119 | + } |
|
120 | + $content .= str_replace('{{notnull}}', $column->getNotnull() ? 'true' : 'false', <<<'EOT' |
|
121 | 121 | 'notnull' => {{notnull}}, |
122 | 122 | |
123 | 123 | EOT |
124 | - ); |
|
125 | - if ($column->getLength() !== null) { |
|
126 | - $content .= str_replace('{{length}}', $column->getLength(), <<<'EOT' |
|
124 | + ); |
|
125 | + if ($column->getLength() !== null) { |
|
126 | + $content .= str_replace('{{length}}', $column->getLength(), <<<'EOT' |
|
127 | 127 | 'length' => {{length}}, |
128 | 128 | |
129 | 129 | EOT |
130 | - ); |
|
131 | - } |
|
132 | - $default = $column->getDefault(); |
|
133 | - if ($default !== null) { |
|
134 | - $default = is_numeric($default) ? $default : "'$default'"; |
|
135 | - $content .= str_replace('{{default}}', $default, <<<'EOT' |
|
130 | + ); |
|
131 | + } |
|
132 | + $default = $column->getDefault(); |
|
133 | + if ($default !== null) { |
|
134 | + $default = is_numeric($default) ? $default : "'$default'"; |
|
135 | + $content .= str_replace('{{default}}', $default, <<<'EOT' |
|
136 | 136 | 'default' => {{default}}, |
137 | 137 | |
138 | 138 | EOT |
139 | - ); |
|
140 | - } |
|
141 | - if ($column->getUnsigned()) { |
|
142 | - $content .= <<<'EOT' |
|
139 | + ); |
|
140 | + } |
|
141 | + if ($column->getUnsigned()) { |
|
142 | + $content .= <<<'EOT' |
|
143 | 143 | 'unsigned' => true, |
144 | 144 | |
145 | 145 | EOT; |
146 | - } |
|
146 | + } |
|
147 | 147 | |
148 | - $content .= <<<'EOT' |
|
148 | + $content .= <<<'EOT' |
|
149 | 149 | ]); |
150 | 150 | |
151 | 151 | EOT; |
152 | - } |
|
152 | + } |
|
153 | 153 | |
154 | - $content .= <<<'EOT' |
|
154 | + $content .= <<<'EOT' |
|
155 | 155 | |
156 | 156 | EOT; |
157 | 157 | |
158 | - $primaryKey = $table->getPrimaryKey(); |
|
159 | - if ($primaryKey !== null) { |
|
160 | - $content .= str_replace('{{columns}}', implode('\', \'', $primaryKey->getUnquotedColumns()), <<<'EOT' |
|
158 | + $primaryKey = $table->getPrimaryKey(); |
|
159 | + if ($primaryKey !== null) { |
|
160 | + $content .= str_replace('{{columns}}', implode('\', \'', $primaryKey->getUnquotedColumns()), <<<'EOT' |
|
161 | 161 | $table->setPrimaryKey(['{{columns}}']); |
162 | 162 | |
163 | 163 | EOT |
164 | - ); |
|
165 | - } |
|
166 | - |
|
167 | - foreach ($table->getIndexes() as $index) { |
|
168 | - if ($index->isPrimary()) { |
|
169 | - continue; |
|
170 | - } |
|
171 | - |
|
172 | - if ($index->isUnique()) { |
|
173 | - $content .= str_replace( |
|
174 | - ['{{columns}}', '{{name}}'], |
|
175 | - [implode('\', \'', $index->getUnquotedColumns()), $index->getName()], |
|
176 | - <<<'EOT' |
|
164 | + ); |
|
165 | + } |
|
166 | + |
|
167 | + foreach ($table->getIndexes() as $index) { |
|
168 | + if ($index->isPrimary()) { |
|
169 | + continue; |
|
170 | + } |
|
171 | + |
|
172 | + if ($index->isUnique()) { |
|
173 | + $content .= str_replace( |
|
174 | + ['{{columns}}', '{{name}}'], |
|
175 | + [implode('\', \'', $index->getUnquotedColumns()), $index->getName()], |
|
176 | + <<<'EOT' |
|
177 | 177 | $table->addUniqueIndex(['{{columns}}'], '{{name}}'); |
178 | 178 | |
179 | 179 | EOT |
180 | - ); |
|
181 | - } else { |
|
182 | - $content .= str_replace( |
|
183 | - ['{{columns}}', '{{name}}'], |
|
184 | - [implode('\', \'', $index->getUnquotedColumns()), $index->getName()], |
|
185 | - <<<'EOT' |
|
180 | + ); |
|
181 | + } else { |
|
182 | + $content .= str_replace( |
|
183 | + ['{{columns}}', '{{name}}'], |
|
184 | + [implode('\', \'', $index->getUnquotedColumns()), $index->getName()], |
|
185 | + <<<'EOT' |
|
186 | 186 | $table->addIndex(['{{columns}}'], '{{name}}'); |
187 | 187 | |
188 | 188 | EOT |
189 | - ); |
|
190 | - } |
|
191 | - } |
|
189 | + ); |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - $content .= <<<'EOT' |
|
193 | + $content .= <<<'EOT' |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | EOT; |
197 | - } |
|
197 | + } |
|
198 | 198 | |
199 | - $content .= <<<'EOT' |
|
199 | + $content .= <<<'EOT' |
|
200 | 200 | return $schema; |
201 | 201 | EOT; |
202 | 202 | |
203 | - return $content; |
|
204 | - } |
|
203 | + return $content; |
|
204 | + } |
|
205 | 205 | } |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | |
36 | 36 | class GenerateCommand extends Command { |
37 | 37 | |
38 | - protected static $_templateSimple = |
|
39 | - '<?php |
|
38 | + protected static $_templateSimple = |
|
39 | + '<?php |
|
40 | 40 | namespace {{namespace}}; |
41 | 41 | |
42 | 42 | use OCP\DB\ISchemaWrapper; |
@@ -79,94 +79,94 @@ discard block |
||
79 | 79 | } |
80 | 80 | '; |
81 | 81 | |
82 | - /** @var IDBConnection */ |
|
83 | - protected $connection; |
|
84 | - |
|
85 | - /** |
|
86 | - * @param IDBConnection $connection |
|
87 | - */ |
|
88 | - public function __construct(IDBConnection $connection) { |
|
89 | - $this->connection = $connection; |
|
90 | - |
|
91 | - parent::__construct(); |
|
92 | - } |
|
93 | - |
|
94 | - protected function configure() { |
|
95 | - $this |
|
96 | - ->setName('migrations:generate') |
|
97 | - ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on') |
|
98 | - ->addArgument('version', InputArgument::REQUIRED, 'Major version of this app, to allow versions on parallel development branches') |
|
99 | - ; |
|
100 | - |
|
101 | - parent::configure(); |
|
102 | - } |
|
103 | - |
|
104 | - public function execute(InputInterface $input, OutputInterface $output) { |
|
105 | - $appName = $input->getArgument('app'); |
|
106 | - $version = $input->getArgument('version'); |
|
107 | - |
|
108 | - if (!preg_match('/^\d{1,16}$/',$version)) { |
|
109 | - $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>'); |
|
110 | - return 1; |
|
111 | - } |
|
112 | - |
|
113 | - $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); |
|
114 | - |
|
115 | - $date = date('YmdHis'); |
|
116 | - $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date); |
|
117 | - |
|
118 | - $output->writeln("New migration class has been generated to <info>$path</info>"); |
|
119 | - return 0; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @param MigrationService $ms |
|
124 | - * @param string $className |
|
125 | - * @param string $schemaBody |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - protected function generateMigration(MigrationService $ms, $className, $schemaBody = '') { |
|
129 | - if ($schemaBody === '') { |
|
130 | - $schemaBody = "\t\t" . 'return null;'; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - $placeHolders = [ |
|
135 | - '{{namespace}}', |
|
136 | - '{{classname}}', |
|
137 | - '{{schemabody}}', |
|
138 | - ]; |
|
139 | - $replacements = [ |
|
140 | - $ms->getMigrationsNamespace(), |
|
141 | - $className, |
|
142 | - $schemaBody, |
|
143 | - ]; |
|
144 | - $code = str_replace($placeHolders, $replacements, self::$_templateSimple); |
|
145 | - $dir = $ms->getMigrationsDirectory(); |
|
146 | - |
|
147 | - $this->ensureMigrationDirExists($dir); |
|
148 | - $path = $dir . '/' . $className . '.php'; |
|
149 | - |
|
150 | - if (file_put_contents($path, $code) === false) { |
|
151 | - throw new RuntimeException('Failed to generate new migration step.'); |
|
152 | - } |
|
153 | - |
|
154 | - return $path; |
|
155 | - } |
|
156 | - |
|
157 | - protected function ensureMigrationDirExists($directory) { |
|
158 | - if (file_exists($directory) && is_dir($directory)) { |
|
159 | - return; |
|
160 | - } |
|
161 | - |
|
162 | - if (file_exists($directory)) { |
|
163 | - throw new \RuntimeException("Could not create folder \"$directory\""); |
|
164 | - } |
|
165 | - |
|
166 | - $this->ensureMigrationDirExists(dirname($directory)); |
|
167 | - |
|
168 | - if (!@mkdir($directory) && !is_dir($directory)) { |
|
169 | - throw new \RuntimeException("Could not create folder \"$directory\""); |
|
170 | - } |
|
171 | - } |
|
82 | + /** @var IDBConnection */ |
|
83 | + protected $connection; |
|
84 | + |
|
85 | + /** |
|
86 | + * @param IDBConnection $connection |
|
87 | + */ |
|
88 | + public function __construct(IDBConnection $connection) { |
|
89 | + $this->connection = $connection; |
|
90 | + |
|
91 | + parent::__construct(); |
|
92 | + } |
|
93 | + |
|
94 | + protected function configure() { |
|
95 | + $this |
|
96 | + ->setName('migrations:generate') |
|
97 | + ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on') |
|
98 | + ->addArgument('version', InputArgument::REQUIRED, 'Major version of this app, to allow versions on parallel development branches') |
|
99 | + ; |
|
100 | + |
|
101 | + parent::configure(); |
|
102 | + } |
|
103 | + |
|
104 | + public function execute(InputInterface $input, OutputInterface $output) { |
|
105 | + $appName = $input->getArgument('app'); |
|
106 | + $version = $input->getArgument('version'); |
|
107 | + |
|
108 | + if (!preg_match('/^\d{1,16}$/',$version)) { |
|
109 | + $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>'); |
|
110 | + return 1; |
|
111 | + } |
|
112 | + |
|
113 | + $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); |
|
114 | + |
|
115 | + $date = date('YmdHis'); |
|
116 | + $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date); |
|
117 | + |
|
118 | + $output->writeln("New migration class has been generated to <info>$path</info>"); |
|
119 | + return 0; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @param MigrationService $ms |
|
124 | + * @param string $className |
|
125 | + * @param string $schemaBody |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + protected function generateMigration(MigrationService $ms, $className, $schemaBody = '') { |
|
129 | + if ($schemaBody === '') { |
|
130 | + $schemaBody = "\t\t" . 'return null;'; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + $placeHolders = [ |
|
135 | + '{{namespace}}', |
|
136 | + '{{classname}}', |
|
137 | + '{{schemabody}}', |
|
138 | + ]; |
|
139 | + $replacements = [ |
|
140 | + $ms->getMigrationsNamespace(), |
|
141 | + $className, |
|
142 | + $schemaBody, |
|
143 | + ]; |
|
144 | + $code = str_replace($placeHolders, $replacements, self::$_templateSimple); |
|
145 | + $dir = $ms->getMigrationsDirectory(); |
|
146 | + |
|
147 | + $this->ensureMigrationDirExists($dir); |
|
148 | + $path = $dir . '/' . $className . '.php'; |
|
149 | + |
|
150 | + if (file_put_contents($path, $code) === false) { |
|
151 | + throw new RuntimeException('Failed to generate new migration step.'); |
|
152 | + } |
|
153 | + |
|
154 | + return $path; |
|
155 | + } |
|
156 | + |
|
157 | + protected function ensureMigrationDirExists($directory) { |
|
158 | + if (file_exists($directory) && is_dir($directory)) { |
|
159 | + return; |
|
160 | + } |
|
161 | + |
|
162 | + if (file_exists($directory)) { |
|
163 | + throw new \RuntimeException("Could not create folder \"$directory\""); |
|
164 | + } |
|
165 | + |
|
166 | + $this->ensureMigrationDirExists(dirname($directory)); |
|
167 | + |
|
168 | + if (!@mkdir($directory) && !is_dir($directory)) { |
|
169 | + throw new \RuntimeException("Could not create folder \"$directory\""); |
|
170 | + } |
|
171 | + } |
|
172 | 172 | } |
@@ -29,50 +29,50 @@ |
||
29 | 29 | |
30 | 30 | class Version13000Date20170814074715 extends SimpleMigrationStep { |
31 | 31 | |
32 | - /** |
|
33 | - * @param IOutput $output |
|
34 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
35 | - * @param array $options |
|
36 | - * @since 13.0.0 |
|
37 | - */ |
|
38 | - public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
39 | - } |
|
32 | + /** |
|
33 | + * @param IOutput $output |
|
34 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
35 | + * @param array $options |
|
36 | + * @since 13.0.0 |
|
37 | + */ |
|
38 | + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param IOutput $output |
|
43 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
44 | - * @param array $options |
|
45 | - * @return null|ISchemaWrapper |
|
46 | - * @since 13.0.0 |
|
47 | - */ |
|
48 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
49 | - /** @var ISchemaWrapper $schema */ |
|
50 | - $schema = $schemaClosure(); |
|
41 | + /** |
|
42 | + * @param IOutput $output |
|
43 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
44 | + * @param array $options |
|
45 | + * @return null|ISchemaWrapper |
|
46 | + * @since 13.0.0 |
|
47 | + */ |
|
48 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
49 | + /** @var ISchemaWrapper $schema */ |
|
50 | + $schema = $schemaClosure(); |
|
51 | 51 | |
52 | 52 | |
53 | - if (!$schema->hasTable('accounts')) { |
|
54 | - $table = $schema->createTable('accounts'); |
|
55 | - $table->addColumn('uid', 'string', [ |
|
56 | - 'notnull' => true, |
|
57 | - 'length' => 64, |
|
58 | - 'default' => '', |
|
59 | - ]); |
|
60 | - $table->addColumn('data', 'text', [ |
|
61 | - 'notnull' => true, |
|
62 | - 'default' => '', |
|
63 | - ]); |
|
64 | - $table->setPrimaryKey(['uid']); |
|
65 | - } |
|
53 | + if (!$schema->hasTable('accounts')) { |
|
54 | + $table = $schema->createTable('accounts'); |
|
55 | + $table->addColumn('uid', 'string', [ |
|
56 | + 'notnull' => true, |
|
57 | + 'length' => 64, |
|
58 | + 'default' => '', |
|
59 | + ]); |
|
60 | + $table->addColumn('data', 'text', [ |
|
61 | + 'notnull' => true, |
|
62 | + 'default' => '', |
|
63 | + ]); |
|
64 | + $table->setPrimaryKey(['uid']); |
|
65 | + } |
|
66 | 66 | |
67 | - return $schema; |
|
68 | - } |
|
67 | + return $schema; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @param IOutput $output |
|
72 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
73 | - * @param array $options |
|
74 | - * @since 13.0.0 |
|
75 | - */ |
|
76 | - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
77 | - } |
|
70 | + /** |
|
71 | + * @param IOutput $output |
|
72 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
73 | + * @param array $options |
|
74 | + * @since 13.0.0 |
|
75 | + */ |
|
76 | + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
77 | + } |
|
78 | 78 | } |
@@ -32,93 +32,93 @@ |
||
32 | 32 | */ |
33 | 33 | class Version13000Date20170919121250 extends SimpleMigrationStep { |
34 | 34 | |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @since 13.0.0 |
|
40 | - */ |
|
41 | - public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @param IOutput $output |
|
46 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
47 | - * @param array $options |
|
48 | - * @return null|ISchemaWrapper |
|
49 | - * @since 13.0.0 |
|
50 | - */ |
|
51 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
52 | - /** @var ISchemaWrapper $schema */ |
|
53 | - $schema = $schemaClosure(); |
|
54 | - |
|
55 | - $table = $schema->getTable('jobs'); |
|
56 | - $column = $table->getColumn('id'); |
|
57 | - $column->setUnsigned(true); |
|
58 | - |
|
59 | - $table = $schema->getTable('authtoken'); |
|
60 | - $column = $table->getColumn('id'); |
|
61 | - $column->setUnsigned(true); |
|
62 | - $column = $table->getColumn('type'); |
|
63 | - $column->setUnsigned(true); |
|
64 | - $column = $table->getColumn('remember'); |
|
65 | - $column->setUnsigned(true); |
|
66 | - $column = $table->getColumn('last_activity'); |
|
67 | - $column->setUnsigned(true); |
|
68 | - $column = $table->getColumn('last_check'); |
|
69 | - $column->setUnsigned(true); |
|
70 | - |
|
71 | - $table = $schema->getTable('bruteforce_attempts'); |
|
72 | - $column = $table->getColumn('id'); |
|
73 | - $column->setUnsigned(true); |
|
74 | - $column = $table->getColumn('occurred'); |
|
75 | - $column->setUnsigned(true); |
|
76 | - |
|
77 | - $table = $schema->getTable('comments'); |
|
78 | - $column = $table->getColumn('id'); |
|
79 | - $column->setUnsigned(true); |
|
80 | - $column = $table->getColumn('parent_id'); |
|
81 | - $column->setUnsigned(true); |
|
82 | - $column = $table->getColumn('topmost_parent_id'); |
|
83 | - $column->setUnsigned(true); |
|
84 | - $column = $table->getColumn('children_count'); |
|
85 | - $column->setUnsigned(true); |
|
86 | - |
|
87 | - $table = $schema->getTable('file_locks'); |
|
88 | - $column = $table->getColumn('id'); |
|
89 | - $column->setUnsigned(true); |
|
90 | - |
|
91 | - $table = $schema->getTable('systemtag'); |
|
92 | - $column = $table->getColumn('id'); |
|
93 | - $column->setUnsigned(true); |
|
94 | - |
|
95 | - $table = $schema->getTable('systemtag_object_mapping'); |
|
96 | - $column = $table->getColumn('systemtagid'); |
|
97 | - $column->setUnsigned(true); |
|
98 | - |
|
99 | - $table = $schema->getTable('systemtag_group'); |
|
100 | - $column = $table->getColumn('systemtagid'); |
|
101 | - $column->setUnsigned(true); |
|
102 | - |
|
103 | - $table = $schema->getTable('vcategory'); |
|
104 | - $column = $table->getColumn('id'); |
|
105 | - $column->setUnsigned(true); |
|
106 | - |
|
107 | - $table = $schema->getTable('vcategory_to_object'); |
|
108 | - $column = $table->getColumn('objid'); |
|
109 | - $column->setUnsigned(true); |
|
110 | - $column = $table->getColumn('categoryid'); |
|
111 | - $column->setUnsigned(true); |
|
112 | - |
|
113 | - return $schema; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @param IOutput $output |
|
118 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
119 | - * @param array $options |
|
120 | - * @since 13.0.0 |
|
121 | - */ |
|
122 | - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
123 | - } |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @since 13.0.0 |
|
40 | + */ |
|
41 | + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @param IOutput $output |
|
46 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
47 | + * @param array $options |
|
48 | + * @return null|ISchemaWrapper |
|
49 | + * @since 13.0.0 |
|
50 | + */ |
|
51 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
52 | + /** @var ISchemaWrapper $schema */ |
|
53 | + $schema = $schemaClosure(); |
|
54 | + |
|
55 | + $table = $schema->getTable('jobs'); |
|
56 | + $column = $table->getColumn('id'); |
|
57 | + $column->setUnsigned(true); |
|
58 | + |
|
59 | + $table = $schema->getTable('authtoken'); |
|
60 | + $column = $table->getColumn('id'); |
|
61 | + $column->setUnsigned(true); |
|
62 | + $column = $table->getColumn('type'); |
|
63 | + $column->setUnsigned(true); |
|
64 | + $column = $table->getColumn('remember'); |
|
65 | + $column->setUnsigned(true); |
|
66 | + $column = $table->getColumn('last_activity'); |
|
67 | + $column->setUnsigned(true); |
|
68 | + $column = $table->getColumn('last_check'); |
|
69 | + $column->setUnsigned(true); |
|
70 | + |
|
71 | + $table = $schema->getTable('bruteforce_attempts'); |
|
72 | + $column = $table->getColumn('id'); |
|
73 | + $column->setUnsigned(true); |
|
74 | + $column = $table->getColumn('occurred'); |
|
75 | + $column->setUnsigned(true); |
|
76 | + |
|
77 | + $table = $schema->getTable('comments'); |
|
78 | + $column = $table->getColumn('id'); |
|
79 | + $column->setUnsigned(true); |
|
80 | + $column = $table->getColumn('parent_id'); |
|
81 | + $column->setUnsigned(true); |
|
82 | + $column = $table->getColumn('topmost_parent_id'); |
|
83 | + $column->setUnsigned(true); |
|
84 | + $column = $table->getColumn('children_count'); |
|
85 | + $column->setUnsigned(true); |
|
86 | + |
|
87 | + $table = $schema->getTable('file_locks'); |
|
88 | + $column = $table->getColumn('id'); |
|
89 | + $column->setUnsigned(true); |
|
90 | + |
|
91 | + $table = $schema->getTable('systemtag'); |
|
92 | + $column = $table->getColumn('id'); |
|
93 | + $column->setUnsigned(true); |
|
94 | + |
|
95 | + $table = $schema->getTable('systemtag_object_mapping'); |
|
96 | + $column = $table->getColumn('systemtagid'); |
|
97 | + $column->setUnsigned(true); |
|
98 | + |
|
99 | + $table = $schema->getTable('systemtag_group'); |
|
100 | + $column = $table->getColumn('systemtagid'); |
|
101 | + $column->setUnsigned(true); |
|
102 | + |
|
103 | + $table = $schema->getTable('vcategory'); |
|
104 | + $column = $table->getColumn('id'); |
|
105 | + $column->setUnsigned(true); |
|
106 | + |
|
107 | + $table = $schema->getTable('vcategory_to_object'); |
|
108 | + $column = $table->getColumn('objid'); |
|
109 | + $column->setUnsigned(true); |
|
110 | + $column = $table->getColumn('categoryid'); |
|
111 | + $column->setUnsigned(true); |
|
112 | + |
|
113 | + return $schema; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @param IOutput $output |
|
118 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
119 | + * @param array $options |
|
120 | + * @since 13.0.0 |
|
121 | + */ |
|
122 | + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
123 | + } |
|
124 | 124 | } |
@@ -29,65 +29,65 @@ |
||
29 | 29 | use OCP\Migration\IOutput; |
30 | 30 | |
31 | 31 | class Version13000Date20170705121758 extends SimpleMigrationStep { |
32 | - /** |
|
33 | - * @param IOutput $output |
|
34 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
35 | - * @param array $options |
|
36 | - * @return null|ISchemaWrapper |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
40 | - /** @var ISchemaWrapper $schema */ |
|
41 | - $schema = $schemaClosure(); |
|
32 | + /** |
|
33 | + * @param IOutput $output |
|
34 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
35 | + * @param array $options |
|
36 | + * @return null|ISchemaWrapper |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
40 | + /** @var ISchemaWrapper $schema */ |
|
41 | + $schema = $schemaClosure(); |
|
42 | 42 | |
43 | - if (!$schema->hasTable('personal_sections')) { |
|
44 | - $table = $schema->createTable('personal_sections'); |
|
43 | + if (!$schema->hasTable('personal_sections')) { |
|
44 | + $table = $schema->createTable('personal_sections'); |
|
45 | 45 | |
46 | - $table->addColumn('id', Type::STRING, [ |
|
47 | - 'notnull' => false, |
|
48 | - 'length' => 64, |
|
49 | - ]); |
|
50 | - $table->addColumn('class', Type::STRING, [ |
|
51 | - 'notnull' => true, |
|
52 | - 'length' => 255, |
|
53 | - ]); |
|
54 | - $table->addColumn('priority', Type::INTEGER, [ |
|
55 | - 'notnull' => true, |
|
56 | - 'length' => 6, |
|
57 | - 'default' => 0, |
|
58 | - ]); |
|
46 | + $table->addColumn('id', Type::STRING, [ |
|
47 | + 'notnull' => false, |
|
48 | + 'length' => 64, |
|
49 | + ]); |
|
50 | + $table->addColumn('class', Type::STRING, [ |
|
51 | + 'notnull' => true, |
|
52 | + 'length' => 255, |
|
53 | + ]); |
|
54 | + $table->addColumn('priority', Type::INTEGER, [ |
|
55 | + 'notnull' => true, |
|
56 | + 'length' => 6, |
|
57 | + 'default' => 0, |
|
58 | + ]); |
|
59 | 59 | |
60 | - $table->setPrimaryKey(['id'], 'personal_sections_id_index'); |
|
61 | - $table->addUniqueIndex(['class'], 'personal_sections_class'); |
|
62 | - } |
|
60 | + $table->setPrimaryKey(['id'], 'personal_sections_id_index'); |
|
61 | + $table->addUniqueIndex(['class'], 'personal_sections_class'); |
|
62 | + } |
|
63 | 63 | |
64 | - if (!$schema->hasTable('personal_settings')) { |
|
65 | - $table = $schema->createTable('personal_settings'); |
|
64 | + if (!$schema->hasTable('personal_settings')) { |
|
65 | + $table = $schema->createTable('personal_settings'); |
|
66 | 66 | |
67 | - $table->addColumn('id', Type::INTEGER, [ |
|
68 | - 'autoincrement' => true, |
|
69 | - 'notnull' => true, |
|
70 | - 'length' => 20, |
|
71 | - ]); |
|
72 | - $table->addColumn('class', Type::STRING, [ |
|
73 | - 'notnull' => true, |
|
74 | - 'length' => 255, |
|
75 | - ]); |
|
76 | - $table->addColumn('section', Type::STRING, [ |
|
77 | - 'notnull' => false, |
|
78 | - 'length' => 64, |
|
79 | - ]); |
|
80 | - $table->addColumn('priority', Type::INTEGER, [ |
|
81 | - 'notnull' => true, |
|
82 | - 'length' => 6, |
|
83 | - 'default' => 0, |
|
84 | - ]); |
|
67 | + $table->addColumn('id', Type::INTEGER, [ |
|
68 | + 'autoincrement' => true, |
|
69 | + 'notnull' => true, |
|
70 | + 'length' => 20, |
|
71 | + ]); |
|
72 | + $table->addColumn('class', Type::STRING, [ |
|
73 | + 'notnull' => true, |
|
74 | + 'length' => 255, |
|
75 | + ]); |
|
76 | + $table->addColumn('section', Type::STRING, [ |
|
77 | + 'notnull' => false, |
|
78 | + 'length' => 64, |
|
79 | + ]); |
|
80 | + $table->addColumn('priority', Type::INTEGER, [ |
|
81 | + 'notnull' => true, |
|
82 | + 'length' => 6, |
|
83 | + 'default' => 0, |
|
84 | + ]); |
|
85 | 85 | |
86 | - $table->setPrimaryKey(['id'], 'personal_settings_id_index'); |
|
87 | - $table->addUniqueIndex(['class'], 'personal_settings_class'); |
|
88 | - $table->addIndex(['section'], 'personal_settings_section'); |
|
89 | - } |
|
86 | + $table->setPrimaryKey(['id'], 'personal_settings_id_index'); |
|
87 | + $table->addUniqueIndex(['class'], 'personal_settings_class'); |
|
88 | + $table->addIndex(['section'], 'personal_settings_section'); |
|
89 | + } |
|
90 | 90 | |
91 | - return $schema; |
|
92 | - } |
|
91 | + return $schema; |
|
92 | + } |
|
93 | 93 | } |
@@ -30,891 +30,891 @@ |
||
30 | 30 | |
31 | 31 | class Version13000Date20170718121200 extends SimpleMigrationStep { |
32 | 32 | |
33 | - /** |
|
34 | - * @param IOutput $output |
|
35 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
36 | - * @param array $options |
|
37 | - * @return null|ISchemaWrapper |
|
38 | - * @since 13.0.0 |
|
39 | - */ |
|
40 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
41 | - /** @var ISchemaWrapper $schema */ |
|
42 | - $schema = $schemaClosure(); |
|
43 | - |
|
44 | - if (!$schema->hasTable('appconfig')) { |
|
45 | - $table = $schema->createTable('appconfig'); |
|
46 | - $table->addColumn('appid', 'string', [ |
|
47 | - 'notnull' => true, |
|
48 | - 'length' => 32, |
|
49 | - 'default' => '', |
|
50 | - ]); |
|
51 | - $table->addColumn('configkey', 'string', [ |
|
52 | - 'notnull' => true, |
|
53 | - 'length' => 64, |
|
54 | - 'default' => '', |
|
55 | - ]); |
|
56 | - $table->addColumn('configvalue', 'text', [ |
|
57 | - 'notnull' => false, |
|
58 | - ]); |
|
59 | - $table->setPrimaryKey(['appid', 'configkey']); |
|
60 | - $table->addIndex(['configkey'], 'appconfig_config_key_index'); |
|
61 | - $table->addIndex(['appid'], 'appconfig_appid_key'); |
|
62 | - } |
|
63 | - |
|
64 | - if (!$schema->hasTable('storages')) { |
|
65 | - $table = $schema->createTable('storages'); |
|
66 | - $table->addColumn('id', 'string', [ |
|
67 | - 'notnull' => false, |
|
68 | - 'length' => 64, |
|
69 | - ]); |
|
70 | - $table->addColumn('numeric_id', Type::BIGINT, [ |
|
71 | - 'autoincrement' => true, |
|
72 | - 'notnull' => true, |
|
73 | - 'length' => 20, |
|
74 | - ]); |
|
75 | - $table->addColumn('available', 'integer', [ |
|
76 | - 'notnull' => true, |
|
77 | - 'default' => 1, |
|
78 | - ]); |
|
79 | - $table->addColumn('last_checked', 'integer', [ |
|
80 | - 'notnull' => false, |
|
81 | - ]); |
|
82 | - $table->setPrimaryKey(['numeric_id']); |
|
83 | - $table->addUniqueIndex(['id'], 'storages_id_index'); |
|
84 | - } |
|
85 | - |
|
86 | - if (!$schema->hasTable('mounts')) { |
|
87 | - $table = $schema->createTable('mounts'); |
|
88 | - $table->addColumn('id', 'integer', [ |
|
89 | - 'autoincrement' => true, |
|
90 | - 'notnull' => true, |
|
91 | - 'length' => 4, |
|
92 | - ]); |
|
93 | - $table->addColumn('storage_id', 'integer', [ |
|
94 | - 'notnull' => true, |
|
95 | - ]); |
|
96 | - $table->addColumn('root_id', 'integer', [ |
|
97 | - 'notnull' => true, |
|
98 | - ]); |
|
99 | - $table->addColumn('user_id', 'string', [ |
|
100 | - 'notnull' => true, |
|
101 | - 'length' => 64, |
|
102 | - ]); |
|
103 | - $table->addColumn('mount_point', 'string', [ |
|
104 | - 'notnull' => true, |
|
105 | - 'length' => 4000, |
|
106 | - ]); |
|
107 | - $table->addColumn('mount_id', 'integer', [ |
|
108 | - 'notnull' => false, |
|
109 | - ]); |
|
110 | - $table->setPrimaryKey(['id']); |
|
111 | - $table->addIndex(['user_id'], 'mounts_user_index'); |
|
112 | - $table->addIndex(['storage_id'], 'mounts_storage_index'); |
|
113 | - $table->addIndex(['root_id'], 'mounts_root_index'); |
|
114 | - $table->addIndex(['mount_id'], 'mounts_mount_id_index'); |
|
115 | - $table->addUniqueIndex(['user_id', 'root_id'], 'mounts_user_root_index'); |
|
116 | - } |
|
117 | - |
|
118 | - if (!$schema->hasTable('mimetypes')) { |
|
119 | - $table = $schema->createTable('mimetypes'); |
|
120 | - $table->addColumn('id', Type::BIGINT, [ |
|
121 | - 'autoincrement' => true, |
|
122 | - 'notnull' => true, |
|
123 | - 'length' => 20, |
|
124 | - ]); |
|
125 | - $table->addColumn('mimetype', 'string', [ |
|
126 | - 'notnull' => true, |
|
127 | - 'length' => 255, |
|
128 | - 'default' => '', |
|
129 | - ]); |
|
130 | - $table->setPrimaryKey(['id']); |
|
131 | - $table->addUniqueIndex(['mimetype'], 'mimetype_id_index'); |
|
132 | - } |
|
133 | - |
|
134 | - if (!$schema->hasTable('filecache')) { |
|
135 | - $table = $schema->createTable('filecache'); |
|
136 | - $table->addColumn('fileid', Type::BIGINT, [ |
|
137 | - 'autoincrement' => true, |
|
138 | - 'notnull' => true, |
|
139 | - 'length' => 20, |
|
140 | - ]); |
|
141 | - $table->addColumn('storage', Type::BIGINT, [ |
|
142 | - 'notnull' => true, |
|
143 | - 'length' => 20, |
|
144 | - 'default' => 0, |
|
145 | - ]); |
|
146 | - $table->addColumn('path', 'string', [ |
|
147 | - 'notnull' => false, |
|
148 | - 'length' => 4000, |
|
149 | - ]); |
|
150 | - $table->addColumn('path_hash', 'string', [ |
|
151 | - 'notnull' => true, |
|
152 | - 'length' => 32, |
|
153 | - 'default' => '', |
|
154 | - ]); |
|
155 | - $table->addColumn('parent', Type::BIGINT, [ |
|
156 | - 'notnull' => true, |
|
157 | - 'length' => 20, |
|
158 | - 'default' => 0, |
|
159 | - ]); |
|
160 | - $table->addColumn('name', 'string', [ |
|
161 | - 'notnull' => false, |
|
162 | - 'length' => 250, |
|
163 | - ]); |
|
164 | - $table->addColumn('mimetype', Type::BIGINT, [ |
|
165 | - 'notnull' => true, |
|
166 | - 'length' => 20, |
|
167 | - 'default' => 0, |
|
168 | - ]); |
|
169 | - $table->addColumn('mimepart', Type::BIGINT, [ |
|
170 | - 'notnull' => true, |
|
171 | - 'length' => 20, |
|
172 | - 'default' => 0, |
|
173 | - ]); |
|
174 | - $table->addColumn('size', 'bigint', [ |
|
175 | - 'notnull' => true, |
|
176 | - 'length' => 8, |
|
177 | - 'default' => 0, |
|
178 | - ]); |
|
179 | - $table->addColumn('mtime', 'integer', [ |
|
180 | - 'notnull' => true, |
|
181 | - 'length' => 4, |
|
182 | - 'default' => 0, |
|
183 | - ]); |
|
184 | - $table->addColumn('storage_mtime', 'integer', [ |
|
185 | - 'notnull' => true, |
|
186 | - 'length' => 4, |
|
187 | - 'default' => 0, |
|
188 | - ]); |
|
189 | - $table->addColumn('encrypted', 'integer', [ |
|
190 | - 'notnull' => true, |
|
191 | - 'length' => 4, |
|
192 | - 'default' => 0, |
|
193 | - ]); |
|
194 | - $table->addColumn('unencrypted_size', 'bigint', [ |
|
195 | - 'notnull' => true, |
|
196 | - 'length' => 8, |
|
197 | - 'default' => 0, |
|
198 | - ]); |
|
199 | - $table->addColumn('etag', 'string', [ |
|
200 | - 'notnull' => false, |
|
201 | - 'length' => 40, |
|
202 | - ]); |
|
203 | - $table->addColumn('permissions', 'integer', [ |
|
204 | - 'notnull' => false, |
|
205 | - 'length' => 4, |
|
206 | - 'default' => 0, |
|
207 | - ]); |
|
208 | - $table->addColumn('checksum', 'string', [ |
|
209 | - 'notnull' => false, |
|
210 | - 'length' => 255, |
|
211 | - ]); |
|
212 | - $table->setPrimaryKey(['fileid']); |
|
213 | - $table->addUniqueIndex(['storage', 'path_hash'], 'fs_storage_path_hash'); |
|
214 | - $table->addIndex(['parent', 'name'], 'fs_parent_name_hash'); |
|
215 | - $table->addIndex(['storage', 'mimetype'], 'fs_storage_mimetype'); |
|
216 | - $table->addIndex(['storage', 'mimepart'], 'fs_storage_mimepart'); |
|
217 | - $table->addIndex(['storage', 'size', 'fileid'], 'fs_storage_size'); |
|
218 | - } |
|
219 | - |
|
220 | - if (!$schema->hasTable('group_user')) { |
|
221 | - $table = $schema->createTable('group_user'); |
|
222 | - $table->addColumn('gid', 'string', [ |
|
223 | - 'notnull' => true, |
|
224 | - 'length' => 64, |
|
225 | - 'default' => '', |
|
226 | - ]); |
|
227 | - $table->addColumn('uid', 'string', [ |
|
228 | - 'notnull' => true, |
|
229 | - 'length' => 64, |
|
230 | - 'default' => '', |
|
231 | - ]); |
|
232 | - $table->setPrimaryKey(['gid', 'uid']); |
|
233 | - $table->addIndex(['uid'], 'gu_uid_index'); |
|
234 | - } |
|
235 | - |
|
236 | - if (!$schema->hasTable('group_admin')) { |
|
237 | - $table = $schema->createTable('group_admin'); |
|
238 | - $table->addColumn('gid', 'string', [ |
|
239 | - 'notnull' => true, |
|
240 | - 'length' => 64, |
|
241 | - 'default' => '', |
|
242 | - ]); |
|
243 | - $table->addColumn('uid', 'string', [ |
|
244 | - 'notnull' => true, |
|
245 | - 'length' => 64, |
|
246 | - 'default' => '', |
|
247 | - ]); |
|
248 | - $table->setPrimaryKey(['gid', 'uid']); |
|
249 | - $table->addIndex(['uid'], 'group_admin_uid'); |
|
250 | - } |
|
251 | - |
|
252 | - if (!$schema->hasTable('groups')) { |
|
253 | - $table = $schema->createTable('groups'); |
|
254 | - $table->addColumn('gid', 'string', [ |
|
255 | - 'notnull' => true, |
|
256 | - 'length' => 64, |
|
257 | - 'default' => '', |
|
258 | - ]); |
|
259 | - $table->setPrimaryKey(['gid']); |
|
260 | - } |
|
261 | - |
|
262 | - if (!$schema->hasTable('preferences')) { |
|
263 | - $table = $schema->createTable('preferences'); |
|
264 | - $table->addColumn('userid', 'string', [ |
|
265 | - 'notnull' => true, |
|
266 | - 'length' => 64, |
|
267 | - 'default' => '', |
|
268 | - ]); |
|
269 | - $table->addColumn('appid', 'string', [ |
|
270 | - 'notnull' => true, |
|
271 | - 'length' => 32, |
|
272 | - 'default' => '', |
|
273 | - ]); |
|
274 | - $table->addColumn('configkey', 'string', [ |
|
275 | - 'notnull' => true, |
|
276 | - 'length' => 64, |
|
277 | - 'default' => '', |
|
278 | - ]); |
|
279 | - $table->addColumn('configvalue', 'text', [ |
|
280 | - 'notnull' => false, |
|
281 | - ]); |
|
282 | - $table->setPrimaryKey(['userid', 'appid', 'configkey']); |
|
283 | - } |
|
284 | - |
|
285 | - if (!$schema->hasTable('properties')) { |
|
286 | - $table = $schema->createTable('properties'); |
|
287 | - $table->addColumn('id', 'integer', [ |
|
288 | - 'autoincrement' => true, |
|
289 | - 'notnull' => true, |
|
290 | - 'length' => 4, |
|
291 | - ]); |
|
292 | - $table->addColumn('userid', 'string', [ |
|
293 | - 'notnull' => true, |
|
294 | - 'length' => 64, |
|
295 | - 'default' => '', |
|
296 | - ]); |
|
297 | - $table->addColumn('propertypath', 'string', [ |
|
298 | - 'notnull' => true, |
|
299 | - 'length' => 255, |
|
300 | - 'default' => '', |
|
301 | - ]); |
|
302 | - $table->addColumn('propertyname', 'string', [ |
|
303 | - 'notnull' => true, |
|
304 | - 'length' => 255, |
|
305 | - 'default' => '', |
|
306 | - ]); |
|
307 | - $table->addColumn('propertyvalue', 'text', [ |
|
308 | - 'notnull' => true, |
|
309 | - ]); |
|
310 | - $table->setPrimaryKey(['id']); |
|
311 | - $table->addIndex(['userid'], 'property_index'); |
|
312 | - } |
|
313 | - |
|
314 | - if (!$schema->hasTable('share')) { |
|
315 | - $table = $schema->createTable('share'); |
|
316 | - $table->addColumn('id', 'integer', [ |
|
317 | - 'autoincrement' => true, |
|
318 | - 'notnull' => true, |
|
319 | - 'length' => 4, |
|
320 | - ]); |
|
321 | - $table->addColumn('share_type', 'smallint', [ |
|
322 | - 'notnull' => true, |
|
323 | - 'length' => 1, |
|
324 | - 'default' => 0, |
|
325 | - ]); |
|
326 | - $table->addColumn('share_with', 'string', [ |
|
327 | - 'notnull' => false, |
|
328 | - 'length' => 255, |
|
329 | - ]); |
|
330 | - $table->addColumn('password', 'string', [ |
|
331 | - 'notnull' => false, |
|
332 | - 'length' => 255, |
|
333 | - ]); |
|
334 | - $table->addColumn('uid_owner', 'string', [ |
|
335 | - 'notnull' => true, |
|
336 | - 'length' => 64, |
|
337 | - 'default' => '', |
|
338 | - ]); |
|
339 | - $table->addColumn('uid_initiator', 'string', [ |
|
340 | - 'notnull' => false, |
|
341 | - 'length' => 64, |
|
342 | - ]); |
|
343 | - $table->addColumn('parent', 'integer', [ |
|
344 | - 'notnull' => false, |
|
345 | - 'length' => 4, |
|
346 | - ]); |
|
347 | - $table->addColumn('item_type', 'string', [ |
|
348 | - 'notnull' => true, |
|
349 | - 'length' => 64, |
|
350 | - 'default' => '', |
|
351 | - ]); |
|
352 | - $table->addColumn('item_source', 'string', [ |
|
353 | - 'notnull' => false, |
|
354 | - 'length' => 255, |
|
355 | - ]); |
|
356 | - $table->addColumn('item_target', 'string', [ |
|
357 | - 'notnull' => false, |
|
358 | - 'length' => 255, |
|
359 | - ]); |
|
360 | - $table->addColumn('file_source', 'integer', [ |
|
361 | - 'notnull' => false, |
|
362 | - 'length' => 4, |
|
363 | - ]); |
|
364 | - $table->addColumn('file_target', 'string', [ |
|
365 | - 'notnull' => false, |
|
366 | - 'length' => 512, |
|
367 | - ]); |
|
368 | - $table->addColumn('permissions', 'smallint', [ |
|
369 | - 'notnull' => true, |
|
370 | - 'length' => 1, |
|
371 | - 'default' => 0, |
|
372 | - ]); |
|
373 | - $table->addColumn('stime', 'bigint', [ |
|
374 | - 'notnull' => true, |
|
375 | - 'length' => 8, |
|
376 | - 'default' => 0, |
|
377 | - ]); |
|
378 | - $table->addColumn('accepted', 'smallint', [ |
|
379 | - 'notnull' => true, |
|
380 | - 'length' => 1, |
|
381 | - 'default' => 0, |
|
382 | - ]); |
|
383 | - $table->addColumn('expiration', 'datetime', [ |
|
384 | - 'notnull' => false, |
|
385 | - ]); |
|
386 | - $table->addColumn('token', 'string', [ |
|
387 | - 'notnull' => false, |
|
388 | - 'length' => 32, |
|
389 | - ]); |
|
390 | - $table->addColumn('mail_send', 'smallint', [ |
|
391 | - 'notnull' => true, |
|
392 | - 'length' => 1, |
|
393 | - 'default' => 0, |
|
394 | - ]); |
|
395 | - $table->addColumn('share_name', 'string', [ |
|
396 | - 'notnull' => false, |
|
397 | - 'length' => 64, |
|
398 | - ]); |
|
399 | - $table->setPrimaryKey(['id']); |
|
400 | - $table->addIndex(['item_type', 'share_type'], 'item_share_type_index'); |
|
401 | - $table->addIndex(['file_source'], 'file_source_index'); |
|
402 | - $table->addIndex(['token'], 'token_index'); |
|
403 | - $table->addIndex(['share_with'], 'share_with_index'); |
|
404 | - } |
|
405 | - |
|
406 | - if (!$schema->hasTable('jobs')) { |
|
407 | - $table = $schema->createTable('jobs'); |
|
408 | - $table->addColumn('id', 'integer', [ |
|
409 | - 'autoincrement' => true, |
|
410 | - 'notnull' => true, |
|
411 | - 'length' => 4, |
|
412 | - 'unsigned' => true, |
|
413 | - ]); |
|
414 | - $table->addColumn('class', 'string', [ |
|
415 | - 'notnull' => true, |
|
416 | - 'length' => 255, |
|
417 | - 'default' => '', |
|
418 | - ]); |
|
419 | - $table->addColumn('argument', 'string', [ |
|
420 | - 'notnull' => true, |
|
421 | - 'length' => 4000, |
|
422 | - 'default' => '', |
|
423 | - ]); |
|
424 | - $table->addColumn('last_run', 'integer', [ |
|
425 | - 'notnull' => false, |
|
426 | - 'default' => 0, |
|
427 | - ]); |
|
428 | - $table->addColumn('last_checked', 'integer', [ |
|
429 | - 'notnull' => false, |
|
430 | - 'default' => 0, |
|
431 | - ]); |
|
432 | - $table->addColumn('reserved_at', 'integer', [ |
|
433 | - 'notnull' => false, |
|
434 | - 'default' => 0, |
|
435 | - ]); |
|
436 | - $table->addColumn('execution_duration', 'integer', [ |
|
437 | - 'notnull' => true, |
|
438 | - 'default' => 0, |
|
439 | - ]); |
|
440 | - $table->setPrimaryKey(['id']); |
|
441 | - $table->addIndex(['class'], 'job_class_index'); |
|
442 | - } |
|
443 | - |
|
444 | - if (!$schema->hasTable('users')) { |
|
445 | - $table = $schema->createTable('users'); |
|
446 | - $table->addColumn('uid', 'string', [ |
|
447 | - 'notnull' => true, |
|
448 | - 'length' => 64, |
|
449 | - 'default' => '', |
|
450 | - ]); |
|
451 | - $table->addColumn('displayname', 'string', [ |
|
452 | - 'notnull' => false, |
|
453 | - 'length' => 64, |
|
454 | - ]); |
|
455 | - $table->addColumn('password', 'string', [ |
|
456 | - 'notnull' => true, |
|
457 | - 'length' => 255, |
|
458 | - 'default' => '', |
|
459 | - ]); |
|
460 | - $table->setPrimaryKey(['uid']); |
|
461 | - } |
|
462 | - |
|
463 | - if (!$schema->hasTable('authtoken')) { |
|
464 | - $table = $schema->createTable('authtoken'); |
|
465 | - $table->addColumn('id', 'integer', [ |
|
466 | - 'autoincrement' => true, |
|
467 | - 'notnull' => true, |
|
468 | - 'length' => 4, |
|
469 | - 'unsigned' => true, |
|
470 | - ]); |
|
471 | - $table->addColumn('uid', 'string', [ |
|
472 | - 'notnull' => true, |
|
473 | - 'length' => 64, |
|
474 | - 'default' => '', |
|
475 | - ]); |
|
476 | - $table->addColumn('login_name', 'string', [ |
|
477 | - 'notnull' => true, |
|
478 | - 'length' => 64, |
|
479 | - 'default' => '', |
|
480 | - ]); |
|
481 | - $table->addColumn('password', 'text', [ |
|
482 | - 'notnull' => false, |
|
483 | - ]); |
|
484 | - $table->addColumn('name', 'text', [ |
|
485 | - 'notnull' => true, |
|
486 | - 'default' => '', |
|
487 | - ]); |
|
488 | - $table->addColumn('token', 'string', [ |
|
489 | - 'notnull' => true, |
|
490 | - 'length' => 200, |
|
491 | - 'default' => '', |
|
492 | - ]); |
|
493 | - $table->addColumn('type', 'smallint', [ |
|
494 | - 'notnull' => true, |
|
495 | - 'length' => 2, |
|
496 | - 'default' => 0, |
|
497 | - 'unsigned' => true, |
|
498 | - ]); |
|
499 | - $table->addColumn('remember', 'smallint', [ |
|
500 | - 'notnull' => true, |
|
501 | - 'length' => 1, |
|
502 | - 'default' => 0, |
|
503 | - 'unsigned' => true, |
|
504 | - ]); |
|
505 | - $table->addColumn('last_activity', 'integer', [ |
|
506 | - 'notnull' => true, |
|
507 | - 'length' => 4, |
|
508 | - 'default' => 0, |
|
509 | - 'unsigned' => true, |
|
510 | - ]); |
|
511 | - $table->addColumn('last_check', 'integer', [ |
|
512 | - 'notnull' => true, |
|
513 | - 'length' => 4, |
|
514 | - 'default' => 0, |
|
515 | - 'unsigned' => true, |
|
516 | - ]); |
|
517 | - $table->addColumn('scope', 'text', [ |
|
518 | - 'notnull' => false, |
|
519 | - ]); |
|
520 | - $table->setPrimaryKey(['id']); |
|
521 | - $table->addUniqueIndex(['token'], 'authtoken_token_index'); |
|
522 | - $table->addIndex(['last_activity'], 'authtoken_last_activity_index'); |
|
523 | - } |
|
524 | - |
|
525 | - if (!$schema->hasTable('bruteforce_attempts')) { |
|
526 | - $table = $schema->createTable('bruteforce_attempts'); |
|
527 | - $table->addColumn('id', 'integer', [ |
|
528 | - 'autoincrement' => true, |
|
529 | - 'notnull' => true, |
|
530 | - 'length' => 4, |
|
531 | - 'unsigned' => true, |
|
532 | - ]); |
|
533 | - $table->addColumn('action', 'string', [ |
|
534 | - 'notnull' => true, |
|
535 | - 'length' => 64, |
|
536 | - 'default' => '', |
|
537 | - ]); |
|
538 | - $table->addColumn('occurred', 'integer', [ |
|
539 | - 'notnull' => true, |
|
540 | - 'length' => 4, |
|
541 | - 'default' => 0, |
|
542 | - 'unsigned' => true, |
|
543 | - ]); |
|
544 | - $table->addColumn('ip', 'string', [ |
|
545 | - 'notnull' => true, |
|
546 | - 'length' => 255, |
|
547 | - 'default' => '', |
|
548 | - ]); |
|
549 | - $table->addColumn('subnet', 'string', [ |
|
550 | - 'notnull' => true, |
|
551 | - 'length' => 255, |
|
552 | - 'default' => '', |
|
553 | - ]); |
|
554 | - $table->addColumn('metadata', 'string', [ |
|
555 | - 'notnull' => true, |
|
556 | - 'length' => 255, |
|
557 | - 'default' => '', |
|
558 | - ]); |
|
559 | - $table->setPrimaryKey(['id']); |
|
560 | - $table->addIndex(['ip'], 'bruteforce_attempts_ip'); |
|
561 | - $table->addIndex(['subnet'], 'bruteforce_attempts_subnet'); |
|
562 | - } |
|
563 | - |
|
564 | - if (!$schema->hasTable('vcategory')) { |
|
565 | - $table = $schema->createTable('vcategory'); |
|
566 | - $table->addColumn('id', 'integer', [ |
|
567 | - 'autoincrement' => true, |
|
568 | - 'notnull' => true, |
|
569 | - 'length' => 4, |
|
570 | - 'unsigned' => true, |
|
571 | - ]); |
|
572 | - $table->addColumn('uid', 'string', [ |
|
573 | - 'notnull' => true, |
|
574 | - 'length' => 64, |
|
575 | - 'default' => '', |
|
576 | - ]); |
|
577 | - $table->addColumn('type', 'string', [ |
|
578 | - 'notnull' => true, |
|
579 | - 'length' => 64, |
|
580 | - 'default' => '', |
|
581 | - ]); |
|
582 | - $table->addColumn('category', 'string', [ |
|
583 | - 'notnull' => true, |
|
584 | - 'length' => 255, |
|
585 | - 'default' => '', |
|
586 | - ]); |
|
587 | - $table->setPrimaryKey(['id']); |
|
588 | - $table->addIndex(['uid'], 'uid_index'); |
|
589 | - $table->addIndex(['type'], 'type_index'); |
|
590 | - $table->addIndex(['category'], 'category_index'); |
|
591 | - } |
|
592 | - |
|
593 | - if (!$schema->hasTable('vcategory_to_object')) { |
|
594 | - $table = $schema->createTable('vcategory_to_object'); |
|
595 | - $table->addColumn('objid', 'integer', [ |
|
596 | - 'notnull' => true, |
|
597 | - 'length' => 4, |
|
598 | - 'default' => 0, |
|
599 | - 'unsigned' => true, |
|
600 | - ]); |
|
601 | - $table->addColumn('categoryid', 'integer', [ |
|
602 | - 'notnull' => true, |
|
603 | - 'length' => 4, |
|
604 | - 'default' => 0, |
|
605 | - 'unsigned' => true, |
|
606 | - ]); |
|
607 | - $table->addColumn('type', 'string', [ |
|
608 | - 'notnull' => true, |
|
609 | - 'length' => 64, |
|
610 | - 'default' => '', |
|
611 | - ]); |
|
612 | - $table->setPrimaryKey(['categoryid', 'objid', 'type']); |
|
613 | - $table->addIndex(['objid', 'type'], 'vcategory_objectd_index'); |
|
614 | - } |
|
615 | - |
|
616 | - if (!$schema->hasTable('systemtag')) { |
|
617 | - $table = $schema->createTable('systemtag'); |
|
618 | - $table->addColumn('id', 'integer', [ |
|
619 | - 'autoincrement' => true, |
|
620 | - 'notnull' => true, |
|
621 | - 'length' => 4, |
|
622 | - 'unsigned' => true, |
|
623 | - ]); |
|
624 | - $table->addColumn('name', 'string', [ |
|
625 | - 'notnull' => true, |
|
626 | - 'length' => 64, |
|
627 | - 'default' => '', |
|
628 | - ]); |
|
629 | - $table->addColumn('visibility', 'smallint', [ |
|
630 | - 'notnull' => true, |
|
631 | - 'length' => 1, |
|
632 | - 'default' => 1, |
|
633 | - ]); |
|
634 | - $table->addColumn('editable', 'smallint', [ |
|
635 | - 'notnull' => true, |
|
636 | - 'length' => 1, |
|
637 | - 'default' => 1, |
|
638 | - ]); |
|
639 | - $table->setPrimaryKey(['id']); |
|
640 | - $table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident'); |
|
641 | - } |
|
642 | - |
|
643 | - if (!$schema->hasTable('systemtag_object_mapping')) { |
|
644 | - $table = $schema->createTable('systemtag_object_mapping'); |
|
645 | - $table->addColumn('objectid', 'string', [ |
|
646 | - 'notnull' => true, |
|
647 | - 'length' => 64, |
|
648 | - 'default' => '', |
|
649 | - ]); |
|
650 | - $table->addColumn('objecttype', 'string', [ |
|
651 | - 'notnull' => true, |
|
652 | - 'length' => 64, |
|
653 | - 'default' => '', |
|
654 | - ]); |
|
655 | - $table->addColumn('systemtagid', 'integer', [ |
|
656 | - 'notnull' => true, |
|
657 | - 'length' => 4, |
|
658 | - 'default' => 0, |
|
659 | - 'unsigned' => true, |
|
660 | - ]); |
|
661 | - $table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping'); |
|
662 | - } |
|
663 | - |
|
664 | - if (!$schema->hasTable('systemtag_group')) { |
|
665 | - $table = $schema->createTable('systemtag_group'); |
|
666 | - $table->addColumn('systemtagid', 'integer', [ |
|
667 | - 'notnull' => true, |
|
668 | - 'length' => 4, |
|
669 | - 'default' => 0, |
|
670 | - 'unsigned' => true, |
|
671 | - ]); |
|
672 | - $table->addColumn('gid', 'string', [ |
|
673 | - 'notnull' => true, |
|
674 | - ]); |
|
675 | - $table->setPrimaryKey(['gid', 'systemtagid']); |
|
676 | - } |
|
677 | - |
|
678 | - if (!$schema->hasTable('file_locks')) { |
|
679 | - $table = $schema->createTable('file_locks'); |
|
680 | - $table->addColumn('id', 'integer', [ |
|
681 | - 'autoincrement' => true, |
|
682 | - 'notnull' => true, |
|
683 | - 'length' => 4, |
|
684 | - 'unsigned' => true, |
|
685 | - ]); |
|
686 | - $table->addColumn('lock', 'integer', [ |
|
687 | - 'notnull' => true, |
|
688 | - 'length' => 4, |
|
689 | - 'default' => 0, |
|
690 | - ]); |
|
691 | - $table->addColumn('key', 'string', [ |
|
692 | - 'notnull' => true, |
|
693 | - 'length' => 64, |
|
694 | - ]); |
|
695 | - $table->addColumn('ttl', 'integer', [ |
|
696 | - 'notnull' => true, |
|
697 | - 'length' => 4, |
|
698 | - 'default' => -1, |
|
699 | - ]); |
|
700 | - $table->setPrimaryKey(['id']); |
|
701 | - $table->addUniqueIndex(['key'], 'lock_key_index'); |
|
702 | - $table->addIndex(['ttl'], 'lock_ttl_index'); |
|
703 | - } |
|
704 | - |
|
705 | - if (!$schema->hasTable('comments')) { |
|
706 | - $table = $schema->createTable('comments'); |
|
707 | - $table->addColumn('id', 'integer', [ |
|
708 | - 'autoincrement' => true, |
|
709 | - 'notnull' => true, |
|
710 | - 'length' => 4, |
|
711 | - 'unsigned' => true, |
|
712 | - ]); |
|
713 | - $table->addColumn('parent_id', 'integer', [ |
|
714 | - 'notnull' => true, |
|
715 | - 'length' => 4, |
|
716 | - 'default' => 0, |
|
717 | - 'unsigned' => true, |
|
718 | - ]); |
|
719 | - $table->addColumn('topmost_parent_id', 'integer', [ |
|
720 | - 'notnull' => true, |
|
721 | - 'length' => 4, |
|
722 | - 'default' => 0, |
|
723 | - 'unsigned' => true, |
|
724 | - ]); |
|
725 | - $table->addColumn('children_count', 'integer', [ |
|
726 | - 'notnull' => true, |
|
727 | - 'length' => 4, |
|
728 | - 'default' => 0, |
|
729 | - 'unsigned' => true, |
|
730 | - ]); |
|
731 | - $table->addColumn('actor_type', 'string', [ |
|
732 | - 'notnull' => true, |
|
733 | - 'length' => 64, |
|
734 | - 'default' => '', |
|
735 | - ]); |
|
736 | - $table->addColumn('actor_id', 'string', [ |
|
737 | - 'notnull' => true, |
|
738 | - 'length' => 64, |
|
739 | - 'default' => '', |
|
740 | - ]); |
|
741 | - $table->addColumn('message', 'text', [ |
|
742 | - 'notnull' => false, |
|
743 | - ]); |
|
744 | - $table->addColumn('verb', 'string', [ |
|
745 | - 'notnull' => false, |
|
746 | - 'length' => 64, |
|
747 | - ]); |
|
748 | - $table->addColumn('creation_timestamp', 'datetime', [ |
|
749 | - 'notnull' => false, |
|
750 | - ]); |
|
751 | - $table->addColumn('latest_child_timestamp', 'datetime', [ |
|
752 | - 'notnull' => false, |
|
753 | - ]); |
|
754 | - $table->addColumn('object_type', 'string', [ |
|
755 | - 'notnull' => true, |
|
756 | - 'length' => 64, |
|
757 | - 'default' => '', |
|
758 | - ]); |
|
759 | - $table->addColumn('object_id', 'string', [ |
|
760 | - 'notnull' => true, |
|
761 | - 'length' => 64, |
|
762 | - 'default' => '', |
|
763 | - ]); |
|
764 | - $table->setPrimaryKey(['id']); |
|
765 | - $table->addIndex(['parent_id'], 'comments_parent_id_index'); |
|
766 | - $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx'); |
|
767 | - $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index'); |
|
768 | - $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index'); |
|
769 | - } |
|
770 | - |
|
771 | - if (!$schema->hasTable('comments_read_markers')) { |
|
772 | - $table = $schema->createTable('comments_read_markers'); |
|
773 | - $table->addColumn('user_id', 'string', [ |
|
774 | - 'notnull' => true, |
|
775 | - 'length' => 64, |
|
776 | - 'default' => '', |
|
777 | - ]); |
|
778 | - $table->addColumn('marker_datetime', 'datetime', [ |
|
779 | - 'notnull' => false, |
|
780 | - ]); |
|
781 | - $table->addColumn('object_type', 'string', [ |
|
782 | - 'notnull' => true, |
|
783 | - 'length' => 64, |
|
784 | - 'default' => '', |
|
785 | - ]); |
|
786 | - $table->addColumn('object_id', 'string', [ |
|
787 | - 'notnull' => true, |
|
788 | - 'length' => 64, |
|
789 | - 'default' => '', |
|
790 | - ]); |
|
791 | - $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index'); |
|
792 | - $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index'); |
|
793 | - } |
|
794 | - |
|
795 | - if (!$schema->hasTable('credentials')) { |
|
796 | - $table = $schema->createTable('credentials'); |
|
797 | - $table->addColumn('user', 'string', [ |
|
798 | - 'notnull' => true, |
|
799 | - 'length' => 64, |
|
800 | - ]); |
|
801 | - $table->addColumn('identifier', 'string', [ |
|
802 | - 'notnull' => true, |
|
803 | - 'length' => 64, |
|
804 | - ]); |
|
805 | - $table->addColumn('credentials', 'text', [ |
|
806 | - 'notnull' => false, |
|
807 | - ]); |
|
808 | - $table->setPrimaryKey(['user', 'identifier']); |
|
809 | - $table->addIndex(['user'], 'credentials_user'); |
|
810 | - } |
|
811 | - |
|
812 | - if (!$schema->hasTable('admin_sections')) { |
|
813 | - $table = $schema->createTable('admin_sections'); |
|
814 | - $table->addColumn('id', 'string', [ |
|
815 | - 'notnull' => true, |
|
816 | - 'length' => 64, |
|
817 | - ]); |
|
818 | - $table->addColumn('class', 'string', [ |
|
819 | - 'notnull' => true, |
|
820 | - 'length' => 255, |
|
821 | - 'default' => '', |
|
822 | - ]); |
|
823 | - $table->addColumn('priority', 'smallint', [ |
|
824 | - 'notnull' => true, |
|
825 | - 'length' => 1, |
|
826 | - 'default' => 0, |
|
827 | - ]); |
|
828 | - $table->setPrimaryKey(['id']); |
|
829 | - $table->addUniqueIndex(['class'], 'admin_sections_class'); |
|
830 | - } |
|
831 | - |
|
832 | - if (!$schema->hasTable('admin_settings')) { |
|
833 | - $table = $schema->createTable('admin_settings'); |
|
834 | - $table->addColumn('id', 'integer', [ |
|
835 | - 'autoincrement' => true, |
|
836 | - 'notnull' => true, |
|
837 | - 'length' => 4, |
|
838 | - ]); |
|
839 | - $table->addColumn('class', 'string', [ |
|
840 | - 'notnull' => true, |
|
841 | - 'length' => 255, |
|
842 | - 'default' => '', |
|
843 | - ]); |
|
844 | - $table->addColumn('section', 'string', [ |
|
845 | - 'notnull' => false, |
|
846 | - 'length' => 64, |
|
847 | - ]); |
|
848 | - $table->addColumn('priority', 'smallint', [ |
|
849 | - 'notnull' => true, |
|
850 | - 'length' => 1, |
|
851 | - 'default' => 0, |
|
852 | - ]); |
|
853 | - $table->setPrimaryKey(['id']); |
|
854 | - $table->addUniqueIndex(['class'], 'admin_settings_class'); |
|
855 | - $table->addIndex(['section'], 'admin_settings_section'); |
|
856 | - } |
|
857 | - |
|
858 | - if (!$schema->hasTable('personal_sections')) { |
|
859 | - $table = $schema->createTable('personal_sections'); |
|
860 | - $table->addColumn('id', 'string', [ |
|
861 | - 'notnull' => true, |
|
862 | - 'length' => 64, |
|
863 | - ]); |
|
864 | - $table->addColumn('class', 'string', [ |
|
865 | - 'notnull' => true, |
|
866 | - 'length' => 255, |
|
867 | - 'default' => '', |
|
868 | - ]); |
|
869 | - $table->addColumn('priority', 'smallint', [ |
|
870 | - 'notnull' => true, |
|
871 | - 'length' => 1, |
|
872 | - 'default' => 0, |
|
873 | - ]); |
|
874 | - $table->setPrimaryKey(['id']); |
|
875 | - $table->addUniqueIndex(['class'], 'personal_sections_class'); |
|
876 | - } |
|
877 | - |
|
878 | - if (!$schema->hasTable('personal_settings')) { |
|
879 | - $table = $schema->createTable('personal_settings'); |
|
880 | - $table->addColumn('id', 'integer', [ |
|
881 | - 'autoincrement' => true, |
|
882 | - 'notnull' => true, |
|
883 | - 'length' => 4, |
|
884 | - ]); |
|
885 | - $table->addColumn('class', 'string', [ |
|
886 | - 'notnull' => true, |
|
887 | - 'length' => 255, |
|
888 | - 'default' => '', |
|
889 | - ]); |
|
890 | - $table->addColumn('section', 'string', [ |
|
891 | - 'notnull' => false, |
|
892 | - 'length' => 64, |
|
893 | - ]); |
|
894 | - $table->addColumn('priority', 'smallint', [ |
|
895 | - 'notnull' => true, |
|
896 | - 'length' => 1, |
|
897 | - 'default' => 0, |
|
898 | - ]); |
|
899 | - $table->setPrimaryKey(['id']); |
|
900 | - $table->addUniqueIndex(['class'], 'personal_settings_class'); |
|
901 | - $table->addIndex(['section'], 'personal_settings_section'); |
|
902 | - } |
|
903 | - |
|
904 | - if (!$schema->hasTable('accounts')) { |
|
905 | - $table = $schema->createTable('accounts'); |
|
906 | - $table->addColumn('uid', 'string', [ |
|
907 | - 'notnull' => true, |
|
908 | - 'length' => 64, |
|
909 | - 'default' => '', |
|
910 | - ]); |
|
911 | - $table->addColumn('data', 'text', [ |
|
912 | - 'notnull' => true, |
|
913 | - 'default' => '', |
|
914 | - ]); |
|
915 | - $table->setPrimaryKey(['uid']); |
|
916 | - } |
|
917 | - return $schema; |
|
918 | - } |
|
33 | + /** |
|
34 | + * @param IOutput $output |
|
35 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
36 | + * @param array $options |
|
37 | + * @return null|ISchemaWrapper |
|
38 | + * @since 13.0.0 |
|
39 | + */ |
|
40 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
41 | + /** @var ISchemaWrapper $schema */ |
|
42 | + $schema = $schemaClosure(); |
|
43 | + |
|
44 | + if (!$schema->hasTable('appconfig')) { |
|
45 | + $table = $schema->createTable('appconfig'); |
|
46 | + $table->addColumn('appid', 'string', [ |
|
47 | + 'notnull' => true, |
|
48 | + 'length' => 32, |
|
49 | + 'default' => '', |
|
50 | + ]); |
|
51 | + $table->addColumn('configkey', 'string', [ |
|
52 | + 'notnull' => true, |
|
53 | + 'length' => 64, |
|
54 | + 'default' => '', |
|
55 | + ]); |
|
56 | + $table->addColumn('configvalue', 'text', [ |
|
57 | + 'notnull' => false, |
|
58 | + ]); |
|
59 | + $table->setPrimaryKey(['appid', 'configkey']); |
|
60 | + $table->addIndex(['configkey'], 'appconfig_config_key_index'); |
|
61 | + $table->addIndex(['appid'], 'appconfig_appid_key'); |
|
62 | + } |
|
63 | + |
|
64 | + if (!$schema->hasTable('storages')) { |
|
65 | + $table = $schema->createTable('storages'); |
|
66 | + $table->addColumn('id', 'string', [ |
|
67 | + 'notnull' => false, |
|
68 | + 'length' => 64, |
|
69 | + ]); |
|
70 | + $table->addColumn('numeric_id', Type::BIGINT, [ |
|
71 | + 'autoincrement' => true, |
|
72 | + 'notnull' => true, |
|
73 | + 'length' => 20, |
|
74 | + ]); |
|
75 | + $table->addColumn('available', 'integer', [ |
|
76 | + 'notnull' => true, |
|
77 | + 'default' => 1, |
|
78 | + ]); |
|
79 | + $table->addColumn('last_checked', 'integer', [ |
|
80 | + 'notnull' => false, |
|
81 | + ]); |
|
82 | + $table->setPrimaryKey(['numeric_id']); |
|
83 | + $table->addUniqueIndex(['id'], 'storages_id_index'); |
|
84 | + } |
|
85 | + |
|
86 | + if (!$schema->hasTable('mounts')) { |
|
87 | + $table = $schema->createTable('mounts'); |
|
88 | + $table->addColumn('id', 'integer', [ |
|
89 | + 'autoincrement' => true, |
|
90 | + 'notnull' => true, |
|
91 | + 'length' => 4, |
|
92 | + ]); |
|
93 | + $table->addColumn('storage_id', 'integer', [ |
|
94 | + 'notnull' => true, |
|
95 | + ]); |
|
96 | + $table->addColumn('root_id', 'integer', [ |
|
97 | + 'notnull' => true, |
|
98 | + ]); |
|
99 | + $table->addColumn('user_id', 'string', [ |
|
100 | + 'notnull' => true, |
|
101 | + 'length' => 64, |
|
102 | + ]); |
|
103 | + $table->addColumn('mount_point', 'string', [ |
|
104 | + 'notnull' => true, |
|
105 | + 'length' => 4000, |
|
106 | + ]); |
|
107 | + $table->addColumn('mount_id', 'integer', [ |
|
108 | + 'notnull' => false, |
|
109 | + ]); |
|
110 | + $table->setPrimaryKey(['id']); |
|
111 | + $table->addIndex(['user_id'], 'mounts_user_index'); |
|
112 | + $table->addIndex(['storage_id'], 'mounts_storage_index'); |
|
113 | + $table->addIndex(['root_id'], 'mounts_root_index'); |
|
114 | + $table->addIndex(['mount_id'], 'mounts_mount_id_index'); |
|
115 | + $table->addUniqueIndex(['user_id', 'root_id'], 'mounts_user_root_index'); |
|
116 | + } |
|
117 | + |
|
118 | + if (!$schema->hasTable('mimetypes')) { |
|
119 | + $table = $schema->createTable('mimetypes'); |
|
120 | + $table->addColumn('id', Type::BIGINT, [ |
|
121 | + 'autoincrement' => true, |
|
122 | + 'notnull' => true, |
|
123 | + 'length' => 20, |
|
124 | + ]); |
|
125 | + $table->addColumn('mimetype', 'string', [ |
|
126 | + 'notnull' => true, |
|
127 | + 'length' => 255, |
|
128 | + 'default' => '', |
|
129 | + ]); |
|
130 | + $table->setPrimaryKey(['id']); |
|
131 | + $table->addUniqueIndex(['mimetype'], 'mimetype_id_index'); |
|
132 | + } |
|
133 | + |
|
134 | + if (!$schema->hasTable('filecache')) { |
|
135 | + $table = $schema->createTable('filecache'); |
|
136 | + $table->addColumn('fileid', Type::BIGINT, [ |
|
137 | + 'autoincrement' => true, |
|
138 | + 'notnull' => true, |
|
139 | + 'length' => 20, |
|
140 | + ]); |
|
141 | + $table->addColumn('storage', Type::BIGINT, [ |
|
142 | + 'notnull' => true, |
|
143 | + 'length' => 20, |
|
144 | + 'default' => 0, |
|
145 | + ]); |
|
146 | + $table->addColumn('path', 'string', [ |
|
147 | + 'notnull' => false, |
|
148 | + 'length' => 4000, |
|
149 | + ]); |
|
150 | + $table->addColumn('path_hash', 'string', [ |
|
151 | + 'notnull' => true, |
|
152 | + 'length' => 32, |
|
153 | + 'default' => '', |
|
154 | + ]); |
|
155 | + $table->addColumn('parent', Type::BIGINT, [ |
|
156 | + 'notnull' => true, |
|
157 | + 'length' => 20, |
|
158 | + 'default' => 0, |
|
159 | + ]); |
|
160 | + $table->addColumn('name', 'string', [ |
|
161 | + 'notnull' => false, |
|
162 | + 'length' => 250, |
|
163 | + ]); |
|
164 | + $table->addColumn('mimetype', Type::BIGINT, [ |
|
165 | + 'notnull' => true, |
|
166 | + 'length' => 20, |
|
167 | + 'default' => 0, |
|
168 | + ]); |
|
169 | + $table->addColumn('mimepart', Type::BIGINT, [ |
|
170 | + 'notnull' => true, |
|
171 | + 'length' => 20, |
|
172 | + 'default' => 0, |
|
173 | + ]); |
|
174 | + $table->addColumn('size', 'bigint', [ |
|
175 | + 'notnull' => true, |
|
176 | + 'length' => 8, |
|
177 | + 'default' => 0, |
|
178 | + ]); |
|
179 | + $table->addColumn('mtime', 'integer', [ |
|
180 | + 'notnull' => true, |
|
181 | + 'length' => 4, |
|
182 | + 'default' => 0, |
|
183 | + ]); |
|
184 | + $table->addColumn('storage_mtime', 'integer', [ |
|
185 | + 'notnull' => true, |
|
186 | + 'length' => 4, |
|
187 | + 'default' => 0, |
|
188 | + ]); |
|
189 | + $table->addColumn('encrypted', 'integer', [ |
|
190 | + 'notnull' => true, |
|
191 | + 'length' => 4, |
|
192 | + 'default' => 0, |
|
193 | + ]); |
|
194 | + $table->addColumn('unencrypted_size', 'bigint', [ |
|
195 | + 'notnull' => true, |
|
196 | + 'length' => 8, |
|
197 | + 'default' => 0, |
|
198 | + ]); |
|
199 | + $table->addColumn('etag', 'string', [ |
|
200 | + 'notnull' => false, |
|
201 | + 'length' => 40, |
|
202 | + ]); |
|
203 | + $table->addColumn('permissions', 'integer', [ |
|
204 | + 'notnull' => false, |
|
205 | + 'length' => 4, |
|
206 | + 'default' => 0, |
|
207 | + ]); |
|
208 | + $table->addColumn('checksum', 'string', [ |
|
209 | + 'notnull' => false, |
|
210 | + 'length' => 255, |
|
211 | + ]); |
|
212 | + $table->setPrimaryKey(['fileid']); |
|
213 | + $table->addUniqueIndex(['storage', 'path_hash'], 'fs_storage_path_hash'); |
|
214 | + $table->addIndex(['parent', 'name'], 'fs_parent_name_hash'); |
|
215 | + $table->addIndex(['storage', 'mimetype'], 'fs_storage_mimetype'); |
|
216 | + $table->addIndex(['storage', 'mimepart'], 'fs_storage_mimepart'); |
|
217 | + $table->addIndex(['storage', 'size', 'fileid'], 'fs_storage_size'); |
|
218 | + } |
|
219 | + |
|
220 | + if (!$schema->hasTable('group_user')) { |
|
221 | + $table = $schema->createTable('group_user'); |
|
222 | + $table->addColumn('gid', 'string', [ |
|
223 | + 'notnull' => true, |
|
224 | + 'length' => 64, |
|
225 | + 'default' => '', |
|
226 | + ]); |
|
227 | + $table->addColumn('uid', 'string', [ |
|
228 | + 'notnull' => true, |
|
229 | + 'length' => 64, |
|
230 | + 'default' => '', |
|
231 | + ]); |
|
232 | + $table->setPrimaryKey(['gid', 'uid']); |
|
233 | + $table->addIndex(['uid'], 'gu_uid_index'); |
|
234 | + } |
|
235 | + |
|
236 | + if (!$schema->hasTable('group_admin')) { |
|
237 | + $table = $schema->createTable('group_admin'); |
|
238 | + $table->addColumn('gid', 'string', [ |
|
239 | + 'notnull' => true, |
|
240 | + 'length' => 64, |
|
241 | + 'default' => '', |
|
242 | + ]); |
|
243 | + $table->addColumn('uid', 'string', [ |
|
244 | + 'notnull' => true, |
|
245 | + 'length' => 64, |
|
246 | + 'default' => '', |
|
247 | + ]); |
|
248 | + $table->setPrimaryKey(['gid', 'uid']); |
|
249 | + $table->addIndex(['uid'], 'group_admin_uid'); |
|
250 | + } |
|
251 | + |
|
252 | + if (!$schema->hasTable('groups')) { |
|
253 | + $table = $schema->createTable('groups'); |
|
254 | + $table->addColumn('gid', 'string', [ |
|
255 | + 'notnull' => true, |
|
256 | + 'length' => 64, |
|
257 | + 'default' => '', |
|
258 | + ]); |
|
259 | + $table->setPrimaryKey(['gid']); |
|
260 | + } |
|
261 | + |
|
262 | + if (!$schema->hasTable('preferences')) { |
|
263 | + $table = $schema->createTable('preferences'); |
|
264 | + $table->addColumn('userid', 'string', [ |
|
265 | + 'notnull' => true, |
|
266 | + 'length' => 64, |
|
267 | + 'default' => '', |
|
268 | + ]); |
|
269 | + $table->addColumn('appid', 'string', [ |
|
270 | + 'notnull' => true, |
|
271 | + 'length' => 32, |
|
272 | + 'default' => '', |
|
273 | + ]); |
|
274 | + $table->addColumn('configkey', 'string', [ |
|
275 | + 'notnull' => true, |
|
276 | + 'length' => 64, |
|
277 | + 'default' => '', |
|
278 | + ]); |
|
279 | + $table->addColumn('configvalue', 'text', [ |
|
280 | + 'notnull' => false, |
|
281 | + ]); |
|
282 | + $table->setPrimaryKey(['userid', 'appid', 'configkey']); |
|
283 | + } |
|
284 | + |
|
285 | + if (!$schema->hasTable('properties')) { |
|
286 | + $table = $schema->createTable('properties'); |
|
287 | + $table->addColumn('id', 'integer', [ |
|
288 | + 'autoincrement' => true, |
|
289 | + 'notnull' => true, |
|
290 | + 'length' => 4, |
|
291 | + ]); |
|
292 | + $table->addColumn('userid', 'string', [ |
|
293 | + 'notnull' => true, |
|
294 | + 'length' => 64, |
|
295 | + 'default' => '', |
|
296 | + ]); |
|
297 | + $table->addColumn('propertypath', 'string', [ |
|
298 | + 'notnull' => true, |
|
299 | + 'length' => 255, |
|
300 | + 'default' => '', |
|
301 | + ]); |
|
302 | + $table->addColumn('propertyname', 'string', [ |
|
303 | + 'notnull' => true, |
|
304 | + 'length' => 255, |
|
305 | + 'default' => '', |
|
306 | + ]); |
|
307 | + $table->addColumn('propertyvalue', 'text', [ |
|
308 | + 'notnull' => true, |
|
309 | + ]); |
|
310 | + $table->setPrimaryKey(['id']); |
|
311 | + $table->addIndex(['userid'], 'property_index'); |
|
312 | + } |
|
313 | + |
|
314 | + if (!$schema->hasTable('share')) { |
|
315 | + $table = $schema->createTable('share'); |
|
316 | + $table->addColumn('id', 'integer', [ |
|
317 | + 'autoincrement' => true, |
|
318 | + 'notnull' => true, |
|
319 | + 'length' => 4, |
|
320 | + ]); |
|
321 | + $table->addColumn('share_type', 'smallint', [ |
|
322 | + 'notnull' => true, |
|
323 | + 'length' => 1, |
|
324 | + 'default' => 0, |
|
325 | + ]); |
|
326 | + $table->addColumn('share_with', 'string', [ |
|
327 | + 'notnull' => false, |
|
328 | + 'length' => 255, |
|
329 | + ]); |
|
330 | + $table->addColumn('password', 'string', [ |
|
331 | + 'notnull' => false, |
|
332 | + 'length' => 255, |
|
333 | + ]); |
|
334 | + $table->addColumn('uid_owner', 'string', [ |
|
335 | + 'notnull' => true, |
|
336 | + 'length' => 64, |
|
337 | + 'default' => '', |
|
338 | + ]); |
|
339 | + $table->addColumn('uid_initiator', 'string', [ |
|
340 | + 'notnull' => false, |
|
341 | + 'length' => 64, |
|
342 | + ]); |
|
343 | + $table->addColumn('parent', 'integer', [ |
|
344 | + 'notnull' => false, |
|
345 | + 'length' => 4, |
|
346 | + ]); |
|
347 | + $table->addColumn('item_type', 'string', [ |
|
348 | + 'notnull' => true, |
|
349 | + 'length' => 64, |
|
350 | + 'default' => '', |
|
351 | + ]); |
|
352 | + $table->addColumn('item_source', 'string', [ |
|
353 | + 'notnull' => false, |
|
354 | + 'length' => 255, |
|
355 | + ]); |
|
356 | + $table->addColumn('item_target', 'string', [ |
|
357 | + 'notnull' => false, |
|
358 | + 'length' => 255, |
|
359 | + ]); |
|
360 | + $table->addColumn('file_source', 'integer', [ |
|
361 | + 'notnull' => false, |
|
362 | + 'length' => 4, |
|
363 | + ]); |
|
364 | + $table->addColumn('file_target', 'string', [ |
|
365 | + 'notnull' => false, |
|
366 | + 'length' => 512, |
|
367 | + ]); |
|
368 | + $table->addColumn('permissions', 'smallint', [ |
|
369 | + 'notnull' => true, |
|
370 | + 'length' => 1, |
|
371 | + 'default' => 0, |
|
372 | + ]); |
|
373 | + $table->addColumn('stime', 'bigint', [ |
|
374 | + 'notnull' => true, |
|
375 | + 'length' => 8, |
|
376 | + 'default' => 0, |
|
377 | + ]); |
|
378 | + $table->addColumn('accepted', 'smallint', [ |
|
379 | + 'notnull' => true, |
|
380 | + 'length' => 1, |
|
381 | + 'default' => 0, |
|
382 | + ]); |
|
383 | + $table->addColumn('expiration', 'datetime', [ |
|
384 | + 'notnull' => false, |
|
385 | + ]); |
|
386 | + $table->addColumn('token', 'string', [ |
|
387 | + 'notnull' => false, |
|
388 | + 'length' => 32, |
|
389 | + ]); |
|
390 | + $table->addColumn('mail_send', 'smallint', [ |
|
391 | + 'notnull' => true, |
|
392 | + 'length' => 1, |
|
393 | + 'default' => 0, |
|
394 | + ]); |
|
395 | + $table->addColumn('share_name', 'string', [ |
|
396 | + 'notnull' => false, |
|
397 | + 'length' => 64, |
|
398 | + ]); |
|
399 | + $table->setPrimaryKey(['id']); |
|
400 | + $table->addIndex(['item_type', 'share_type'], 'item_share_type_index'); |
|
401 | + $table->addIndex(['file_source'], 'file_source_index'); |
|
402 | + $table->addIndex(['token'], 'token_index'); |
|
403 | + $table->addIndex(['share_with'], 'share_with_index'); |
|
404 | + } |
|
405 | + |
|
406 | + if (!$schema->hasTable('jobs')) { |
|
407 | + $table = $schema->createTable('jobs'); |
|
408 | + $table->addColumn('id', 'integer', [ |
|
409 | + 'autoincrement' => true, |
|
410 | + 'notnull' => true, |
|
411 | + 'length' => 4, |
|
412 | + 'unsigned' => true, |
|
413 | + ]); |
|
414 | + $table->addColumn('class', 'string', [ |
|
415 | + 'notnull' => true, |
|
416 | + 'length' => 255, |
|
417 | + 'default' => '', |
|
418 | + ]); |
|
419 | + $table->addColumn('argument', 'string', [ |
|
420 | + 'notnull' => true, |
|
421 | + 'length' => 4000, |
|
422 | + 'default' => '', |
|
423 | + ]); |
|
424 | + $table->addColumn('last_run', 'integer', [ |
|
425 | + 'notnull' => false, |
|
426 | + 'default' => 0, |
|
427 | + ]); |
|
428 | + $table->addColumn('last_checked', 'integer', [ |
|
429 | + 'notnull' => false, |
|
430 | + 'default' => 0, |
|
431 | + ]); |
|
432 | + $table->addColumn('reserved_at', 'integer', [ |
|
433 | + 'notnull' => false, |
|
434 | + 'default' => 0, |
|
435 | + ]); |
|
436 | + $table->addColumn('execution_duration', 'integer', [ |
|
437 | + 'notnull' => true, |
|
438 | + 'default' => 0, |
|
439 | + ]); |
|
440 | + $table->setPrimaryKey(['id']); |
|
441 | + $table->addIndex(['class'], 'job_class_index'); |
|
442 | + } |
|
443 | + |
|
444 | + if (!$schema->hasTable('users')) { |
|
445 | + $table = $schema->createTable('users'); |
|
446 | + $table->addColumn('uid', 'string', [ |
|
447 | + 'notnull' => true, |
|
448 | + 'length' => 64, |
|
449 | + 'default' => '', |
|
450 | + ]); |
|
451 | + $table->addColumn('displayname', 'string', [ |
|
452 | + 'notnull' => false, |
|
453 | + 'length' => 64, |
|
454 | + ]); |
|
455 | + $table->addColumn('password', 'string', [ |
|
456 | + 'notnull' => true, |
|
457 | + 'length' => 255, |
|
458 | + 'default' => '', |
|
459 | + ]); |
|
460 | + $table->setPrimaryKey(['uid']); |
|
461 | + } |
|
462 | + |
|
463 | + if (!$schema->hasTable('authtoken')) { |
|
464 | + $table = $schema->createTable('authtoken'); |
|
465 | + $table->addColumn('id', 'integer', [ |
|
466 | + 'autoincrement' => true, |
|
467 | + 'notnull' => true, |
|
468 | + 'length' => 4, |
|
469 | + 'unsigned' => true, |
|
470 | + ]); |
|
471 | + $table->addColumn('uid', 'string', [ |
|
472 | + 'notnull' => true, |
|
473 | + 'length' => 64, |
|
474 | + 'default' => '', |
|
475 | + ]); |
|
476 | + $table->addColumn('login_name', 'string', [ |
|
477 | + 'notnull' => true, |
|
478 | + 'length' => 64, |
|
479 | + 'default' => '', |
|
480 | + ]); |
|
481 | + $table->addColumn('password', 'text', [ |
|
482 | + 'notnull' => false, |
|
483 | + ]); |
|
484 | + $table->addColumn('name', 'text', [ |
|
485 | + 'notnull' => true, |
|
486 | + 'default' => '', |
|
487 | + ]); |
|
488 | + $table->addColumn('token', 'string', [ |
|
489 | + 'notnull' => true, |
|
490 | + 'length' => 200, |
|
491 | + 'default' => '', |
|
492 | + ]); |
|
493 | + $table->addColumn('type', 'smallint', [ |
|
494 | + 'notnull' => true, |
|
495 | + 'length' => 2, |
|
496 | + 'default' => 0, |
|
497 | + 'unsigned' => true, |
|
498 | + ]); |
|
499 | + $table->addColumn('remember', 'smallint', [ |
|
500 | + 'notnull' => true, |
|
501 | + 'length' => 1, |
|
502 | + 'default' => 0, |
|
503 | + 'unsigned' => true, |
|
504 | + ]); |
|
505 | + $table->addColumn('last_activity', 'integer', [ |
|
506 | + 'notnull' => true, |
|
507 | + 'length' => 4, |
|
508 | + 'default' => 0, |
|
509 | + 'unsigned' => true, |
|
510 | + ]); |
|
511 | + $table->addColumn('last_check', 'integer', [ |
|
512 | + 'notnull' => true, |
|
513 | + 'length' => 4, |
|
514 | + 'default' => 0, |
|
515 | + 'unsigned' => true, |
|
516 | + ]); |
|
517 | + $table->addColumn('scope', 'text', [ |
|
518 | + 'notnull' => false, |
|
519 | + ]); |
|
520 | + $table->setPrimaryKey(['id']); |
|
521 | + $table->addUniqueIndex(['token'], 'authtoken_token_index'); |
|
522 | + $table->addIndex(['last_activity'], 'authtoken_last_activity_index'); |
|
523 | + } |
|
524 | + |
|
525 | + if (!$schema->hasTable('bruteforce_attempts')) { |
|
526 | + $table = $schema->createTable('bruteforce_attempts'); |
|
527 | + $table->addColumn('id', 'integer', [ |
|
528 | + 'autoincrement' => true, |
|
529 | + 'notnull' => true, |
|
530 | + 'length' => 4, |
|
531 | + 'unsigned' => true, |
|
532 | + ]); |
|
533 | + $table->addColumn('action', 'string', [ |
|
534 | + 'notnull' => true, |
|
535 | + 'length' => 64, |
|
536 | + 'default' => '', |
|
537 | + ]); |
|
538 | + $table->addColumn('occurred', 'integer', [ |
|
539 | + 'notnull' => true, |
|
540 | + 'length' => 4, |
|
541 | + 'default' => 0, |
|
542 | + 'unsigned' => true, |
|
543 | + ]); |
|
544 | + $table->addColumn('ip', 'string', [ |
|
545 | + 'notnull' => true, |
|
546 | + 'length' => 255, |
|
547 | + 'default' => '', |
|
548 | + ]); |
|
549 | + $table->addColumn('subnet', 'string', [ |
|
550 | + 'notnull' => true, |
|
551 | + 'length' => 255, |
|
552 | + 'default' => '', |
|
553 | + ]); |
|
554 | + $table->addColumn('metadata', 'string', [ |
|
555 | + 'notnull' => true, |
|
556 | + 'length' => 255, |
|
557 | + 'default' => '', |
|
558 | + ]); |
|
559 | + $table->setPrimaryKey(['id']); |
|
560 | + $table->addIndex(['ip'], 'bruteforce_attempts_ip'); |
|
561 | + $table->addIndex(['subnet'], 'bruteforce_attempts_subnet'); |
|
562 | + } |
|
563 | + |
|
564 | + if (!$schema->hasTable('vcategory')) { |
|
565 | + $table = $schema->createTable('vcategory'); |
|
566 | + $table->addColumn('id', 'integer', [ |
|
567 | + 'autoincrement' => true, |
|
568 | + 'notnull' => true, |
|
569 | + 'length' => 4, |
|
570 | + 'unsigned' => true, |
|
571 | + ]); |
|
572 | + $table->addColumn('uid', 'string', [ |
|
573 | + 'notnull' => true, |
|
574 | + 'length' => 64, |
|
575 | + 'default' => '', |
|
576 | + ]); |
|
577 | + $table->addColumn('type', 'string', [ |
|
578 | + 'notnull' => true, |
|
579 | + 'length' => 64, |
|
580 | + 'default' => '', |
|
581 | + ]); |
|
582 | + $table->addColumn('category', 'string', [ |
|
583 | + 'notnull' => true, |
|
584 | + 'length' => 255, |
|
585 | + 'default' => '', |
|
586 | + ]); |
|
587 | + $table->setPrimaryKey(['id']); |
|
588 | + $table->addIndex(['uid'], 'uid_index'); |
|
589 | + $table->addIndex(['type'], 'type_index'); |
|
590 | + $table->addIndex(['category'], 'category_index'); |
|
591 | + } |
|
592 | + |
|
593 | + if (!$schema->hasTable('vcategory_to_object')) { |
|
594 | + $table = $schema->createTable('vcategory_to_object'); |
|
595 | + $table->addColumn('objid', 'integer', [ |
|
596 | + 'notnull' => true, |
|
597 | + 'length' => 4, |
|
598 | + 'default' => 0, |
|
599 | + 'unsigned' => true, |
|
600 | + ]); |
|
601 | + $table->addColumn('categoryid', 'integer', [ |
|
602 | + 'notnull' => true, |
|
603 | + 'length' => 4, |
|
604 | + 'default' => 0, |
|
605 | + 'unsigned' => true, |
|
606 | + ]); |
|
607 | + $table->addColumn('type', 'string', [ |
|
608 | + 'notnull' => true, |
|
609 | + 'length' => 64, |
|
610 | + 'default' => '', |
|
611 | + ]); |
|
612 | + $table->setPrimaryKey(['categoryid', 'objid', 'type']); |
|
613 | + $table->addIndex(['objid', 'type'], 'vcategory_objectd_index'); |
|
614 | + } |
|
615 | + |
|
616 | + if (!$schema->hasTable('systemtag')) { |
|
617 | + $table = $schema->createTable('systemtag'); |
|
618 | + $table->addColumn('id', 'integer', [ |
|
619 | + 'autoincrement' => true, |
|
620 | + 'notnull' => true, |
|
621 | + 'length' => 4, |
|
622 | + 'unsigned' => true, |
|
623 | + ]); |
|
624 | + $table->addColumn('name', 'string', [ |
|
625 | + 'notnull' => true, |
|
626 | + 'length' => 64, |
|
627 | + 'default' => '', |
|
628 | + ]); |
|
629 | + $table->addColumn('visibility', 'smallint', [ |
|
630 | + 'notnull' => true, |
|
631 | + 'length' => 1, |
|
632 | + 'default' => 1, |
|
633 | + ]); |
|
634 | + $table->addColumn('editable', 'smallint', [ |
|
635 | + 'notnull' => true, |
|
636 | + 'length' => 1, |
|
637 | + 'default' => 1, |
|
638 | + ]); |
|
639 | + $table->setPrimaryKey(['id']); |
|
640 | + $table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident'); |
|
641 | + } |
|
642 | + |
|
643 | + if (!$schema->hasTable('systemtag_object_mapping')) { |
|
644 | + $table = $schema->createTable('systemtag_object_mapping'); |
|
645 | + $table->addColumn('objectid', 'string', [ |
|
646 | + 'notnull' => true, |
|
647 | + 'length' => 64, |
|
648 | + 'default' => '', |
|
649 | + ]); |
|
650 | + $table->addColumn('objecttype', 'string', [ |
|
651 | + 'notnull' => true, |
|
652 | + 'length' => 64, |
|
653 | + 'default' => '', |
|
654 | + ]); |
|
655 | + $table->addColumn('systemtagid', 'integer', [ |
|
656 | + 'notnull' => true, |
|
657 | + 'length' => 4, |
|
658 | + 'default' => 0, |
|
659 | + 'unsigned' => true, |
|
660 | + ]); |
|
661 | + $table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping'); |
|
662 | + } |
|
663 | + |
|
664 | + if (!$schema->hasTable('systemtag_group')) { |
|
665 | + $table = $schema->createTable('systemtag_group'); |
|
666 | + $table->addColumn('systemtagid', 'integer', [ |
|
667 | + 'notnull' => true, |
|
668 | + 'length' => 4, |
|
669 | + 'default' => 0, |
|
670 | + 'unsigned' => true, |
|
671 | + ]); |
|
672 | + $table->addColumn('gid', 'string', [ |
|
673 | + 'notnull' => true, |
|
674 | + ]); |
|
675 | + $table->setPrimaryKey(['gid', 'systemtagid']); |
|
676 | + } |
|
677 | + |
|
678 | + if (!$schema->hasTable('file_locks')) { |
|
679 | + $table = $schema->createTable('file_locks'); |
|
680 | + $table->addColumn('id', 'integer', [ |
|
681 | + 'autoincrement' => true, |
|
682 | + 'notnull' => true, |
|
683 | + 'length' => 4, |
|
684 | + 'unsigned' => true, |
|
685 | + ]); |
|
686 | + $table->addColumn('lock', 'integer', [ |
|
687 | + 'notnull' => true, |
|
688 | + 'length' => 4, |
|
689 | + 'default' => 0, |
|
690 | + ]); |
|
691 | + $table->addColumn('key', 'string', [ |
|
692 | + 'notnull' => true, |
|
693 | + 'length' => 64, |
|
694 | + ]); |
|
695 | + $table->addColumn('ttl', 'integer', [ |
|
696 | + 'notnull' => true, |
|
697 | + 'length' => 4, |
|
698 | + 'default' => -1, |
|
699 | + ]); |
|
700 | + $table->setPrimaryKey(['id']); |
|
701 | + $table->addUniqueIndex(['key'], 'lock_key_index'); |
|
702 | + $table->addIndex(['ttl'], 'lock_ttl_index'); |
|
703 | + } |
|
704 | + |
|
705 | + if (!$schema->hasTable('comments')) { |
|
706 | + $table = $schema->createTable('comments'); |
|
707 | + $table->addColumn('id', 'integer', [ |
|
708 | + 'autoincrement' => true, |
|
709 | + 'notnull' => true, |
|
710 | + 'length' => 4, |
|
711 | + 'unsigned' => true, |
|
712 | + ]); |
|
713 | + $table->addColumn('parent_id', 'integer', [ |
|
714 | + 'notnull' => true, |
|
715 | + 'length' => 4, |
|
716 | + 'default' => 0, |
|
717 | + 'unsigned' => true, |
|
718 | + ]); |
|
719 | + $table->addColumn('topmost_parent_id', 'integer', [ |
|
720 | + 'notnull' => true, |
|
721 | + 'length' => 4, |
|
722 | + 'default' => 0, |
|
723 | + 'unsigned' => true, |
|
724 | + ]); |
|
725 | + $table->addColumn('children_count', 'integer', [ |
|
726 | + 'notnull' => true, |
|
727 | + 'length' => 4, |
|
728 | + 'default' => 0, |
|
729 | + 'unsigned' => true, |
|
730 | + ]); |
|
731 | + $table->addColumn('actor_type', 'string', [ |
|
732 | + 'notnull' => true, |
|
733 | + 'length' => 64, |
|
734 | + 'default' => '', |
|
735 | + ]); |
|
736 | + $table->addColumn('actor_id', 'string', [ |
|
737 | + 'notnull' => true, |
|
738 | + 'length' => 64, |
|
739 | + 'default' => '', |
|
740 | + ]); |
|
741 | + $table->addColumn('message', 'text', [ |
|
742 | + 'notnull' => false, |
|
743 | + ]); |
|
744 | + $table->addColumn('verb', 'string', [ |
|
745 | + 'notnull' => false, |
|
746 | + 'length' => 64, |
|
747 | + ]); |
|
748 | + $table->addColumn('creation_timestamp', 'datetime', [ |
|
749 | + 'notnull' => false, |
|
750 | + ]); |
|
751 | + $table->addColumn('latest_child_timestamp', 'datetime', [ |
|
752 | + 'notnull' => false, |
|
753 | + ]); |
|
754 | + $table->addColumn('object_type', 'string', [ |
|
755 | + 'notnull' => true, |
|
756 | + 'length' => 64, |
|
757 | + 'default' => '', |
|
758 | + ]); |
|
759 | + $table->addColumn('object_id', 'string', [ |
|
760 | + 'notnull' => true, |
|
761 | + 'length' => 64, |
|
762 | + 'default' => '', |
|
763 | + ]); |
|
764 | + $table->setPrimaryKey(['id']); |
|
765 | + $table->addIndex(['parent_id'], 'comments_parent_id_index'); |
|
766 | + $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx'); |
|
767 | + $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index'); |
|
768 | + $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index'); |
|
769 | + } |
|
770 | + |
|
771 | + if (!$schema->hasTable('comments_read_markers')) { |
|
772 | + $table = $schema->createTable('comments_read_markers'); |
|
773 | + $table->addColumn('user_id', 'string', [ |
|
774 | + 'notnull' => true, |
|
775 | + 'length' => 64, |
|
776 | + 'default' => '', |
|
777 | + ]); |
|
778 | + $table->addColumn('marker_datetime', 'datetime', [ |
|
779 | + 'notnull' => false, |
|
780 | + ]); |
|
781 | + $table->addColumn('object_type', 'string', [ |
|
782 | + 'notnull' => true, |
|
783 | + 'length' => 64, |
|
784 | + 'default' => '', |
|
785 | + ]); |
|
786 | + $table->addColumn('object_id', 'string', [ |
|
787 | + 'notnull' => true, |
|
788 | + 'length' => 64, |
|
789 | + 'default' => '', |
|
790 | + ]); |
|
791 | + $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index'); |
|
792 | + $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index'); |
|
793 | + } |
|
794 | + |
|
795 | + if (!$schema->hasTable('credentials')) { |
|
796 | + $table = $schema->createTable('credentials'); |
|
797 | + $table->addColumn('user', 'string', [ |
|
798 | + 'notnull' => true, |
|
799 | + 'length' => 64, |
|
800 | + ]); |
|
801 | + $table->addColumn('identifier', 'string', [ |
|
802 | + 'notnull' => true, |
|
803 | + 'length' => 64, |
|
804 | + ]); |
|
805 | + $table->addColumn('credentials', 'text', [ |
|
806 | + 'notnull' => false, |
|
807 | + ]); |
|
808 | + $table->setPrimaryKey(['user', 'identifier']); |
|
809 | + $table->addIndex(['user'], 'credentials_user'); |
|
810 | + } |
|
811 | + |
|
812 | + if (!$schema->hasTable('admin_sections')) { |
|
813 | + $table = $schema->createTable('admin_sections'); |
|
814 | + $table->addColumn('id', 'string', [ |
|
815 | + 'notnull' => true, |
|
816 | + 'length' => 64, |
|
817 | + ]); |
|
818 | + $table->addColumn('class', 'string', [ |
|
819 | + 'notnull' => true, |
|
820 | + 'length' => 255, |
|
821 | + 'default' => '', |
|
822 | + ]); |
|
823 | + $table->addColumn('priority', 'smallint', [ |
|
824 | + 'notnull' => true, |
|
825 | + 'length' => 1, |
|
826 | + 'default' => 0, |
|
827 | + ]); |
|
828 | + $table->setPrimaryKey(['id']); |
|
829 | + $table->addUniqueIndex(['class'], 'admin_sections_class'); |
|
830 | + } |
|
831 | + |
|
832 | + if (!$schema->hasTable('admin_settings')) { |
|
833 | + $table = $schema->createTable('admin_settings'); |
|
834 | + $table->addColumn('id', 'integer', [ |
|
835 | + 'autoincrement' => true, |
|
836 | + 'notnull' => true, |
|
837 | + 'length' => 4, |
|
838 | + ]); |
|
839 | + $table->addColumn('class', 'string', [ |
|
840 | + 'notnull' => true, |
|
841 | + 'length' => 255, |
|
842 | + 'default' => '', |
|
843 | + ]); |
|
844 | + $table->addColumn('section', 'string', [ |
|
845 | + 'notnull' => false, |
|
846 | + 'length' => 64, |
|
847 | + ]); |
|
848 | + $table->addColumn('priority', 'smallint', [ |
|
849 | + 'notnull' => true, |
|
850 | + 'length' => 1, |
|
851 | + 'default' => 0, |
|
852 | + ]); |
|
853 | + $table->setPrimaryKey(['id']); |
|
854 | + $table->addUniqueIndex(['class'], 'admin_settings_class'); |
|
855 | + $table->addIndex(['section'], 'admin_settings_section'); |
|
856 | + } |
|
857 | + |
|
858 | + if (!$schema->hasTable('personal_sections')) { |
|
859 | + $table = $schema->createTable('personal_sections'); |
|
860 | + $table->addColumn('id', 'string', [ |
|
861 | + 'notnull' => true, |
|
862 | + 'length' => 64, |
|
863 | + ]); |
|
864 | + $table->addColumn('class', 'string', [ |
|
865 | + 'notnull' => true, |
|
866 | + 'length' => 255, |
|
867 | + 'default' => '', |
|
868 | + ]); |
|
869 | + $table->addColumn('priority', 'smallint', [ |
|
870 | + 'notnull' => true, |
|
871 | + 'length' => 1, |
|
872 | + 'default' => 0, |
|
873 | + ]); |
|
874 | + $table->setPrimaryKey(['id']); |
|
875 | + $table->addUniqueIndex(['class'], 'personal_sections_class'); |
|
876 | + } |
|
877 | + |
|
878 | + if (!$schema->hasTable('personal_settings')) { |
|
879 | + $table = $schema->createTable('personal_settings'); |
|
880 | + $table->addColumn('id', 'integer', [ |
|
881 | + 'autoincrement' => true, |
|
882 | + 'notnull' => true, |
|
883 | + 'length' => 4, |
|
884 | + ]); |
|
885 | + $table->addColumn('class', 'string', [ |
|
886 | + 'notnull' => true, |
|
887 | + 'length' => 255, |
|
888 | + 'default' => '', |
|
889 | + ]); |
|
890 | + $table->addColumn('section', 'string', [ |
|
891 | + 'notnull' => false, |
|
892 | + 'length' => 64, |
|
893 | + ]); |
|
894 | + $table->addColumn('priority', 'smallint', [ |
|
895 | + 'notnull' => true, |
|
896 | + 'length' => 1, |
|
897 | + 'default' => 0, |
|
898 | + ]); |
|
899 | + $table->setPrimaryKey(['id']); |
|
900 | + $table->addUniqueIndex(['class'], 'personal_settings_class'); |
|
901 | + $table->addIndex(['section'], 'personal_settings_section'); |
|
902 | + } |
|
903 | + |
|
904 | + if (!$schema->hasTable('accounts')) { |
|
905 | + $table = $schema->createTable('accounts'); |
|
906 | + $table->addColumn('uid', 'string', [ |
|
907 | + 'notnull' => true, |
|
908 | + 'length' => 64, |
|
909 | + 'default' => '', |
|
910 | + ]); |
|
911 | + $table->addColumn('data', 'text', [ |
|
912 | + 'notnull' => true, |
|
913 | + 'default' => '', |
|
914 | + ]); |
|
915 | + $table->setPrimaryKey(['uid']); |
|
916 | + } |
|
917 | + return $schema; |
|
918 | + } |
|
919 | 919 | |
920 | 920 | } |
@@ -31,75 +31,75 @@ |
||
31 | 31 | |
32 | 32 | class Version1002Date20170607113030 extends SimpleMigrationStep { |
33 | 33 | |
34 | - /** @var IDBConnection */ |
|
35 | - protected $connection; |
|
34 | + /** @var IDBConnection */ |
|
35 | + protected $connection; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param IDBConnection $connection |
|
39 | - */ |
|
40 | - public function __construct(IDBConnection $connection) { |
|
41 | - $this->connection = $connection; |
|
42 | - } |
|
37 | + /** |
|
38 | + * @param IDBConnection $connection |
|
39 | + */ |
|
40 | + public function __construct(IDBConnection $connection) { |
|
41 | + $this->connection = $connection; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param IOutput $output |
|
46 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
47 | - * @param array $options |
|
48 | - * @since 13.0.0 |
|
49 | - */ |
|
50 | - public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
51 | - /** @var ISchemaWrapper $schema */ |
|
52 | - $schema = $schemaClosure(); |
|
44 | + /** |
|
45 | + * @param IOutput $output |
|
46 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
47 | + * @param array $options |
|
48 | + * @since 13.0.0 |
|
49 | + */ |
|
50 | + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
51 | + /** @var ISchemaWrapper $schema */ |
|
52 | + $schema = $schemaClosure(); |
|
53 | 53 | |
54 | - if (!$schema->hasTable('twofactor_backup_codes')) { |
|
55 | - // Legacy table does not exist |
|
56 | - return; |
|
57 | - } |
|
54 | + if (!$schema->hasTable('twofactor_backup_codes')) { |
|
55 | + // Legacy table does not exist |
|
56 | + return; |
|
57 | + } |
|
58 | 58 | |
59 | - $insert = $this->connection->getQueryBuilder(); |
|
60 | - $insert->insert('twofactor_backupcodes') |
|
61 | - ->values([ |
|
62 | - // Inserting with id might fail: 'id' => $insert->createParameter('id'), |
|
63 | - 'user_id' => $insert->createParameter('user_id'), |
|
64 | - 'code' => $insert->createParameter('code'), |
|
65 | - 'used' => $insert->createParameter('used'), |
|
66 | - ]); |
|
59 | + $insert = $this->connection->getQueryBuilder(); |
|
60 | + $insert->insert('twofactor_backupcodes') |
|
61 | + ->values([ |
|
62 | + // Inserting with id might fail: 'id' => $insert->createParameter('id'), |
|
63 | + 'user_id' => $insert->createParameter('user_id'), |
|
64 | + 'code' => $insert->createParameter('code'), |
|
65 | + 'used' => $insert->createParameter('used'), |
|
66 | + ]); |
|
67 | 67 | |
68 | - $query = $this->connection->getQueryBuilder(); |
|
69 | - $query->select('*') |
|
70 | - ->from('twofactor_backup_codes') |
|
71 | - ->orderBy('id', 'ASC'); |
|
72 | - $result = $query->execute(); |
|
68 | + $query = $this->connection->getQueryBuilder(); |
|
69 | + $query->select('*') |
|
70 | + ->from('twofactor_backup_codes') |
|
71 | + ->orderBy('id', 'ASC'); |
|
72 | + $result = $query->execute(); |
|
73 | 73 | |
74 | - $output->startProgress(); |
|
75 | - while ($row = $result->fetch()) { |
|
76 | - $output->advance(); |
|
74 | + $output->startProgress(); |
|
75 | + while ($row = $result->fetch()) { |
|
76 | + $output->advance(); |
|
77 | 77 | |
78 | - $insert |
|
79 | - // Inserting with id might fail: ->setParameter('id', $row['id'], IQueryBuilder::PARAM_INT) |
|
80 | - ->setParameter('user_id', $row['user_id'], IQueryBuilder::PARAM_STR) |
|
81 | - ->setParameter('code', $row['code'], IQueryBuilder::PARAM_STR) |
|
82 | - ->setParameter('used', $row['used'], IQueryBuilder::PARAM_INT) |
|
83 | - ->execute(); |
|
84 | - } |
|
85 | - $output->finishProgress(); |
|
86 | - } |
|
78 | + $insert |
|
79 | + // Inserting with id might fail: ->setParameter('id', $row['id'], IQueryBuilder::PARAM_INT) |
|
80 | + ->setParameter('user_id', $row['user_id'], IQueryBuilder::PARAM_STR) |
|
81 | + ->setParameter('code', $row['code'], IQueryBuilder::PARAM_STR) |
|
82 | + ->setParameter('used', $row['used'], IQueryBuilder::PARAM_INT) |
|
83 | + ->execute(); |
|
84 | + } |
|
85 | + $output->finishProgress(); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @param IOutput $output |
|
90 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
91 | - * @param array $options |
|
92 | - * @return null|ISchemaWrapper |
|
93 | - * @since 13.0.0 |
|
94 | - */ |
|
95 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
96 | - /** @var ISchemaWrapper $schema */ |
|
97 | - $schema = $schemaClosure(); |
|
88 | + /** |
|
89 | + * @param IOutput $output |
|
90 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
91 | + * @param array $options |
|
92 | + * @return null|ISchemaWrapper |
|
93 | + * @since 13.0.0 |
|
94 | + */ |
|
95 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
96 | + /** @var ISchemaWrapper $schema */ |
|
97 | + $schema = $schemaClosure(); |
|
98 | 98 | |
99 | - if ($schema->hasTable('twofactor_backup_codes')) { |
|
100 | - $schema->dropTable('twofactor_backup_codes'); |
|
101 | - return $schema; |
|
102 | - } |
|
103 | - return null; |
|
104 | - } |
|
99 | + if ($schema->hasTable('twofactor_backup_codes')) { |
|
100 | + $schema->dropTable('twofactor_backup_codes'); |
|
101 | + return $schema; |
|
102 | + } |
|
103 | + return null; |
|
104 | + } |
|
105 | 105 | } |
@@ -30,27 +30,27 @@ |
||
30 | 30 | |
31 | 31 | class Version1002Date20170919123342 extends SimpleMigrationStep { |
32 | 32 | |
33 | - /** |
|
34 | - * @param IOutput $output |
|
35 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
36 | - * @param array $options |
|
37 | - * @return null|ISchemaWrapper |
|
38 | - * @since 13.0.0 |
|
39 | - */ |
|
40 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
41 | - /** @var ISchemaWrapper $schema */ |
|
42 | - $schema = $schemaClosure(); |
|
33 | + /** |
|
34 | + * @param IOutput $output |
|
35 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
36 | + * @param array $options |
|
37 | + * @return null|ISchemaWrapper |
|
38 | + * @since 13.0.0 |
|
39 | + */ |
|
40 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
41 | + /** @var ISchemaWrapper $schema */ |
|
42 | + $schema = $schemaClosure(); |
|
43 | 43 | |
44 | - $table = $schema->getTable('twofactor_backupcodes'); |
|
45 | - $column = $table->getColumn('user_id'); |
|
46 | - $column->setDefault(''); |
|
44 | + $table = $schema->getTable('twofactor_backupcodes'); |
|
45 | + $column = $table->getColumn('user_id'); |
|
46 | + $column->setDefault(''); |
|
47 | 47 | |
48 | - $column = $table->getColumn('used'); |
|
49 | - if ($column->getType()->getName() !== Type::SMALLINT) { |
|
50 | - $column->setType(Type::getType(Type::SMALLINT)); |
|
51 | - $column->setOptions(['length' => 6]); |
|
52 | - } |
|
48 | + $column = $table->getColumn('used'); |
|
49 | + if ($column->getType()->getName() !== Type::SMALLINT) { |
|
50 | + $column->setType(Type::getType(Type::SMALLINT)); |
|
51 | + $column->setOptions(['length' => 6]); |
|
52 | + } |
|
53 | 53 | |
54 | - return $schema; |
|
55 | - } |
|
54 | + return $schema; |
|
55 | + } |
|
56 | 56 | } |