diff --git a/community_server/db/skeema/gradido_community/migrations.sql b/community_server/db/skeema/gradido_community/migrations.sql new file mode 100644 index 000000000..7665bcf29 --- /dev/null +++ b/community_server/db/skeema/gradido_community/migrations.sql @@ -0,0 +1,5 @@ +CREATE TABLE `migrations` ( + `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `db_version` int DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/src/Controller/MigrationsController.php b/community_server/src/Controller/MigrationsController.php new file mode 100644 index 000000000..93a1b8044 --- /dev/null +++ b/community_server/src/Controller/MigrationsController.php @@ -0,0 +1,106 @@ +paginate($this->Migrations); + + $this->set(compact('migrations')); + } + + /** + * View method + * + * @param string|null $id Migration id. + * @return \Cake\Http\Response|null + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function view($id = null) + { + $migration = $this->Migrations->get($id, [ + 'contain' => [], + ]); + + $this->set('migration', $migration); + } + + /** + * Add method + * + * @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise. + */ + public function add() + { + $migration = $this->Migrations->newEntity(); + if ($this->request->is('post')) { + $migration = $this->Migrations->patchEntity($migration, $this->request->getData()); + if ($this->Migrations->save($migration)) { + $this->Flash->success(__('The migration has been saved.')); + + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The migration could not be saved. Please, try again.')); + } + $this->set(compact('migration')); + } + + /** + * Edit method + * + * @param string|null $id Migration id. + * @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise. + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function edit($id = null) + { + $migration = $this->Migrations->get($id, [ + 'contain' => [], + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + $migration = $this->Migrations->patchEntity($migration, $this->request->getData()); + if ($this->Migrations->save($migration)) { + $this->Flash->success(__('The migration has been saved.')); + + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The migration could not be saved. Please, try again.')); + } + $this->set(compact('migration')); + } + + /** + * Delete method + * + * @param string|null $id Migration id. + * @return \Cake\Http\Response|null Redirects to index. + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function delete($id = null) + { + $this->request->allowMethod(['post', 'delete']); + $migration = $this->Migrations->get($id); + if ($this->Migrations->delete($migration)) { + $this->Flash->success(__('The migration has been deleted.')); + } else { + $this->Flash->error(__('The migration could not be deleted. Please, try again.')); + } + + return $this->redirect(['action' => 'index']); + } +} diff --git a/community_server/src/Model/Entity/Migration.php b/community_server/src/Model/Entity/Migration.php new file mode 100644 index 000000000..700136cf8 --- /dev/null +++ b/community_server/src/Model/Entity/Migration.php @@ -0,0 +1,26 @@ + true, + ]; +} diff --git a/community_server/src/Model/Table/MigrationsTable.php b/community_server/src/Model/Table/MigrationsTable.php new file mode 100644 index 000000000..b5cb42154 --- /dev/null +++ b/community_server/src/Model/Table/MigrationsTable.php @@ -0,0 +1,56 @@ +setTable('migrations'); + $this->setDisplayField('id'); + $this->setPrimaryKey('id'); + } + + /** + * Default validation rules. + * + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator + */ + public function validationDefault(Validator $validator) + { + $validator + ->nonNegativeInteger('id') + ->allowEmptyString('id', null, 'create'); + + $validator + ->integer('db_version') + ->allowEmptyString('db_version'); + + return $validator; + } +} diff --git a/community_server/src/Template/Migrations/add.ctp b/community_server/src/Template/Migrations/add.ctp new file mode 100644 index 000000000..94a555733 --- /dev/null +++ b/community_server/src/Template/Migrations/add.ctp @@ -0,0 +1,23 @@ + + +
| = $this->Paginator->sort('id') ?> | += $this->Paginator->sort('db_version') ?> | += __('Actions') ?> | +
|---|---|---|
| = $this->Number->format($migration->id) ?> | += $this->Number->format($migration->db_version) ?> | ++ = $this->Html->link(__('View'), ['action' => 'view', $migration->id]) ?> + = $this->Html->link(__('Edit'), ['action' => 'edit', $migration->id]) ?> + = $this->Form->postLink(__('Delete'), ['action' => 'delete', $migration->id], ['confirm' => __('Are you sure you want to delete # {0}?', $migration->id)]) ?> + | +
= $this->Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')]) ?>
+| = __('Id') ?> | += $this->Number->format($migration->id) ?> | +
|---|---|
| = __('Db Version') ?> | += $this->Number->format($migration->db_version) ?> | +