|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright (c) 2020 Danny Damsky |
| 5 | + * |
| 6 | + * Redistribution and use in source and binary forms, with or without |
| 7 | + * modification, are permitted provided that the following conditions |
| 8 | + * are met: |
| 9 | + * 1. Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
| 11 | + * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | + * notice, this list of conditions and the following disclaimer in the |
| 13 | + * documentation and/or other materials provided with the distribution. |
| 14 | + * 3. Neither the name of the author nor the names of its contributors may |
| 15 | + * be used to endorse or promote products derived from this software |
| 16 | + * |
| 17 | + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 18 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 21 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | + * SUCH DAMAGE. |
| 28 | + */ |
| 29 | + |
| 30 | +namespace DannyDamsky\DevTools\Api; |
| 31 | + |
| 32 | +use Magento\Framework\DB\Ddl\Table; |
| 33 | +use Magento\Framework\Model\AbstractModel; |
| 34 | + |
| 35 | +/** |
| 36 | + * Interface BlueprintInterface |
| 37 | + * |
| 38 | + * A data class that is used to hold a table's schema blueprint. |
| 39 | + * |
| 40 | + * @package DannyDamsky\DevTools\Api |
| 41 | + * @since 2020-03-27 |
| 42 | + * @author Danny Damsky <dannydamsky99@gmail.com> |
| 43 | + */ |
| 44 | +interface BlueprintInterface |
| 45 | +{ |
| 46 | + /** |
| 47 | + * Create a boolean column. |
| 48 | + * |
| 49 | + * @param string $columnName |
| 50 | + * @return ColumnDefinitionInterface|AbstractModel |
| 51 | + */ |
| 52 | + public function boolean(string $columnName): ColumnDefinitionInterface; |
| 53 | + |
| 54 | + /** |
| 55 | + * Create a small integer column. |
| 56 | + * |
| 57 | + * @param string $columnName |
| 58 | + * @param bool $unsigned |
| 59 | + * @return ColumnDefinitionInterface|AbstractModel |
| 60 | + */ |
| 61 | + public function smallint(string $columnName, bool $unsigned = false): ColumnDefinitionInterface; |
| 62 | + |
| 63 | + /** |
| 64 | + * Create an integer column. |
| 65 | + * |
| 66 | + * @param string $columnName |
| 67 | + * @param bool $unsigned |
| 68 | + * @return ColumnDefinitionInterface|AbstractModel |
| 69 | + */ |
| 70 | + public function integer(string $columnName, bool $unsigned = false): ColumnDefinitionInterface; |
| 71 | + |
| 72 | + /** |
| 73 | + * Create a big integer column. |
| 74 | + * |
| 75 | + * @param string $columnName |
| 76 | + * @param bool $unsigned |
| 77 | + * @return ColumnDefinitionInterface|AbstractModel |
| 78 | + */ |
| 79 | + public function bigint(string $columnName, bool $unsigned = false): ColumnDefinitionInterface; |
| 80 | + |
| 81 | + /** |
| 82 | + * Create a float column. |
| 83 | + * |
| 84 | + * @param string $columnName |
| 85 | + * @param bool $unsigned |
| 86 | + * @return ColumnDefinitionInterface|AbstractModel |
| 87 | + */ |
| 88 | + public function float(string $columnName, bool $unsigned = false): ColumnDefinitionInterface; |
| 89 | + |
| 90 | + /** |
| 91 | + * Create a numeric column. |
| 92 | + * |
| 93 | + * @param string $columnName |
| 94 | + * @param bool $unsigned |
| 95 | + * @param int|null $size |
| 96 | + * @return ColumnDefinitionInterface|AbstractModel |
| 97 | + */ |
| 98 | + public function numeric(string $columnName, bool $unsigned = false, ?int $size = null): ColumnDefinitionInterface; |
| 99 | + |
| 100 | + /** |
| 101 | + * Create a date column. |
| 102 | + * |
| 103 | + * @param string $columnName |
| 104 | + * @return ColumnDefinitionInterface|AbstractModel |
| 105 | + */ |
| 106 | + public function date(string $columnName): ColumnDefinitionInterface; |
| 107 | + |
| 108 | + /** |
| 109 | + * Create a timestamp column. |
| 110 | + * |
| 111 | + * @param string $columnName |
| 112 | + * @return ColumnDefinitionInterface|AbstractModel |
| 113 | + */ |
| 114 | + public function timestamp(string $columnName): ColumnDefinitionInterface; |
| 115 | + |
| 116 | + /** |
| 117 | + * Create a creation timestamp column. |
| 118 | + * |
| 119 | + * @param string $columnName |
| 120 | + * @return ColumnDefinitionInterface|AbstractModel |
| 121 | + */ |
| 122 | + public function creationTimestamp(string $columnName = 'created_at'): ColumnDefinitionInterface; |
| 123 | + |
| 124 | + /** |
| 125 | + * Create a modification timestamp column. |
| 126 | + * |
| 127 | + * @param string $columnName |
| 128 | + * @return ColumnDefinitionInterface|AbstractModel |
| 129 | + */ |
| 130 | + public function modificationTimestamp(string $columnName = 'updated_at'): ColumnDefinitionInterface; |
| 131 | + |
| 132 | + /** |
| 133 | + * Create creation and modification timestamp columns. |
| 134 | + * |
| 135 | + * @param string $createdAtColumnName |
| 136 | + * @param string $updatedAtColumnName |
| 137 | + */ |
| 138 | + public function timestamps(string $createdAtColumnName = 'created_at', string $updatedAtColumnName = 'updated_at'): void; |
| 139 | + |
| 140 | + /** |
| 141 | + * Create a date time column. |
| 142 | + * |
| 143 | + * @param string $columnName |
| 144 | + * @return ColumnDefinitionInterface|AbstractModel |
| 145 | + */ |
| 146 | + public function dateTime(string $columnName): ColumnDefinitionInterface; |
| 147 | + |
| 148 | + /** |
| 149 | + * Create a text column. |
| 150 | + * |
| 151 | + * @param string $columnName |
| 152 | + * @param int|null $size |
| 153 | + * @return ColumnDefinitionInterface|AbstractModel |
| 154 | + */ |
| 155 | + public function text(string $columnName, ?int $size = null): ColumnDefinitionInterface; |
| 156 | + |
| 157 | + /** |
| 158 | + * Create a blob column. |
| 159 | + * |
| 160 | + * @param string $columnName |
| 161 | + * @return ColumnDefinitionInterface|AbstractModel |
| 162 | + */ |
| 163 | + public function blob(string $columnName): ColumnDefinitionInterface; |
| 164 | + |
| 165 | + /** |
| 166 | + * Create a varbinary column. |
| 167 | + * |
| 168 | + * @param string $columnName |
| 169 | + * @return ColumnDefinitionInterface|AbstractModel |
| 170 | + */ |
| 171 | + public function varbinary(string $columnName): ColumnDefinitionInterface; |
| 172 | + |
| 173 | + /** |
| 174 | + * Add Foreign Key to table |
| 175 | + * |
| 176 | + * @param string $fkName the foreign key name |
| 177 | + * @param string $column the foreign key column name |
| 178 | + * @param string $refTable the reference table name |
| 179 | + * @param string $refColumn the reference table column name |
| 180 | + * @param string $onDelete the action on delete row |
| 181 | + */ |
| 182 | + public function addForeignKey(string $fkName, string $column, string $refTable, string $refColumn, ?string $onDelete = null): void; |
| 183 | + |
| 184 | + /** |
| 185 | + * Add index to table. |
| 186 | + * |
| 187 | + * @param string $indexName |
| 188 | + * @param string|array $fields |
| 189 | + * @param array $options |
| 190 | + */ |
| 191 | + public function addIndex(string $indexName, $fields, array $options = []): void; |
| 192 | + |
| 193 | + /** |
| 194 | + * Get the list of all column definitions that were created. |
| 195 | + * |
| 196 | + * @return ColumnDefinitionInterface[]|AbstractModel[] |
| 197 | + */ |
| 198 | + public function getColumnDefinitions(): array; |
| 199 | + |
| 200 | + /** |
| 201 | + * Get the list of all foreign key definitions that were created. |
| 202 | + * |
| 203 | + * @return array |
| 204 | + */ |
| 205 | + public function getForeignKeyDefinitions(): array; |
| 206 | + |
| 207 | + /** |
| 208 | + * Get the list of all index definitions that were created. |
| 209 | + * |
| 210 | + * @return array |
| 211 | + */ |
| 212 | + public function getIndexDefinitions(): array; |
| 213 | +} |
0 commit comments