Open Monograph Press  3.3.0
OMPMigration.inc.php
1 <?php
2 
14 use Illuminate\Database\Migrations\Migration;
15 use Illuminate\Database\Schema\Builder;
16 use Illuminate\Database\Schema\Blueprint;
17 use Illuminate\Database\Capsule\Manager as Capsule;
18 
19 class OMPMigration extends Migration {
24  public function up() {
25  Capsule::schema()->create('identification_codes', function (Blueprint $table) {
26  $table->bigInteger('identification_code_id')->autoIncrement();
27  $table->bigInteger('publication_format_id');
28  $table->string('code', 40);
29  $table->string('value', 255);
30  $table->index(['identification_code_id', 'publication_format_id', 'code'], 'identification_codes_key');
31  });
32 
33  Capsule::schema()->create('publication_dates', function (Blueprint $table) {
34  $table->bigInteger('publication_date_id')->autoIncrement();
35  $table->bigInteger('publication_format_id');
36  $table->string('role', 40);
37  $table->string('date_format', 40);
38  $table->string('date', 255);
39  $table->index(['publication_date_id', 'publication_format_id', 'role'], 'format_publication_dates_pkey');
40  });
41 
42  Capsule::schema()->create('sales_rights', function (Blueprint $table) {
43  $table->bigInteger('sales_rights_id')->autoIncrement();
44  $table->bigInteger('publication_format_id');
45  $table->string('type', 40);
46  // ROW is 'rest of world'. ROW sales types have no territories assigned to them
47  $table->smallInteger('row_setting')->default(0);
48  $table->text('countries_included')->nullable();
49  $table->text('countries_excluded')->nullable();
50  $table->text('regions_included')->nullable();
51  $table->text('regions_excluded')->nullable();
52  $table->index(['sales_rights_id', 'publication_format_id'], 'format_sales_rights_pkey');
53  });
54 
55  Capsule::schema()->create('markets', function (Blueprint $table) {
56  $table->bigInteger('market_id')->autoIncrement();
57  $table->bigInteger('publication_format_id');
58  $table->text('countries_included')->nullable();
59  $table->text('countries_excluded')->nullable();
60  $table->text('regions_included')->nullable();
61  $table->text('regions_excluded')->nullable();
62  $table->string('market_date_role', 40);
63  $table->string('market_date_format', 40);
64  $table->string('market_date', 255);
65  $table->string('price', 255)->nullable();
66  $table->string('discount', 255)->nullable();
67  $table->string('price_type_code', 255)->nullable();
68  $table->string('currency_code', 255)->nullable();
69  $table->string('tax_rate_code', 255)->nullable();
70  $table->string('tax_type_code', 255)->nullable();
71  $table->bigInteger('agent_id')->nullable();
72  $table->bigInteger('supplier_id')->nullable();
73  $table->index(['market_id', 'publication_format_id'], 'format_markets_pkey');
74  });
75 
76  Capsule::schema()->create('representatives', function (Blueprint $table) {
77  $table->bigInteger('representative_id')->autoIncrement();
78  $table->bigInteger('submission_id');
79  $table->string('role', 40);
80  $table->string('representative_id_type', 255)->nullable();
81  $table->string('representative_id_value', 255)->nullable();
82  $table->string('name', 255)->nullable();
83  $table->string('phone', 255)->nullable();
84  $table->string('email', 255)->nullable();
85  $table->string('url', 2047)->nullable();
86  $table->smallInteger('is_supplier')->default(1);
87  $table->index(['representative_id', 'submission_id'], 'format_representatives_pkey');
88  });
89 
90  Capsule::schema()->create('features', function (Blueprint $table) {
91  $table->bigInteger('submission_id');
92  $table->bigInteger('assoc_type');
93  $table->bigInteger('assoc_id');
94  $table->bigInteger('seq');
95  $table->unique(['assoc_type', 'assoc_id', 'submission_id'], 'press_features_pkey');
96  });
97 
98  Capsule::schema()->create('new_releases', function (Blueprint $table) {
99  $table->bigInteger('submission_id');
100  $table->bigInteger('assoc_type');
101  $table->bigInteger('assoc_id');
102  $table->unique(['assoc_type', 'assoc_id', 'submission_id'], 'new_releases_pkey');
103  });
104 
105  // Press series.
106  Capsule::schema()->create('series', function (Blueprint $table) {
107  $table->bigInteger('series_id')->autoIncrement();
108  $table->bigInteger('press_id');
109  $table->bigInteger('review_form_id')->nullable();
110  // NOTNULL not included for the sake of 1.1 upgrade, which didn't include this column
111  $table->float('seq', 8, 2)->default(0)->nullable();
112  $table->smallInteger('featured')->default(0);
113  $table->smallInteger('editor_restricted')->default(0);
114  $table->string('path', 255);
115  $table->text('image')->nullable();
116  $table->smallInteger('is_inactive')->default(0);
117  $table->index(['press_id'], 'series_press_id');
118  $table->unique(['press_id', 'path'], 'series_path');
119  });
120 
121  // Series-specific settings
122  Capsule::schema()->create('series_settings', function (Blueprint $table) {
123  $table->bigInteger('series_id');
124  $table->string('locale', 14)->default('');
125  $table->string('setting_name', 255);
126  $table->text('setting_value')->nullable();
127  $table->string('setting_type', 6)->comment('(bool|int|float|string|object)');
128  $table->unique(['series_id', 'locale', 'setting_name'], 'series_settings_pkey');
129  });
130 
131  // Associations for categories within a series.
132  Capsule::schema()->create('series_categories', function (Blueprint $table) {
133  $table->bigInteger('series_id');
134  $table->bigInteger('category_id');
135  $table->unique(['series_id', 'category_id'], 'series_categories_id');
136  });
137 
138  // Publications
139  Capsule::schema()->create('publications', function (Blueprint $table) {
140  $table->bigInteger('publication_id')->autoIncrement();
141  $table->date('date_published')->nullable();
142  $table->datetime('last_modified')->nullable();
143  $table->string('locale', 14)->nullable();
144  $table->bigInteger('primary_contact_id')->nullable();
145  $table->string('publication_date_type', 32)->default('pub')->nullable();
146  // PUBLICATION_TYPE_PUBLICATION
147  $table->string('publication_type', 32)->default('publication')->nullable();
148  $table->float('seq', 8, 2)->default(0);
149  $table->bigInteger('series_id')->nullable();
150  $table->string('series_position', 255)->nullable();
151  $table->bigInteger('submission_id');
152  $table->smallInteger('status')->default(1);
153  $table->string('url_path', 64)->nullable();
154  $table->bigInteger('version')->nullable();
155  $table->index(['submission_id'], 'publications_submission_id');
156  $table->index(['series_id'], 'publications_section_id');
157  });
158 
159  // Publication formats assigned to published submissions
160  Capsule::schema()->create('publication_formats', function (Blueprint $table) {
161  $table->bigInteger('publication_format_id')->autoIncrement();
162  $table->bigInteger('publication_id');
163  // DEPRECATED: Held over for the OJS 2.x to 3. upgrade process pkp/pkp-lib#3572
164  $table->bigInteger('submission_id')->nullable();
165  $table->smallInteger('physical_format')->default(1)->nullable();
166  $table->string('entry_key', 64)->nullable();
167  $table->float('seq', 8, 2)->default(0);
168  $table->string('file_size', 255)->nullable();
169  $table->string('front_matter', 255)->nullable();
170  $table->string('back_matter', 255)->nullable();
171  $table->string('height', 255)->nullable();
172  $table->string('height_unit_code', 255)->nullable();
173  $table->string('width', 255)->nullable();
174  $table->string('width_unit_code', 255)->nullable();
175  $table->string('thickness', 255)->nullable();
176  $table->string('thickness_unit_code', 255)->nullable();
177  $table->string('weight', 255)->nullable();
178  $table->string('weight_unit_code', 255)->nullable();
179  $table->string('product_composition_code', 255)->nullable();
180  $table->string('product_form_detail_code', 255)->nullable();
181  $table->string('country_manufacture_code', 255)->nullable();
182  $table->string('imprint', 255)->nullable();
183  $table->string('product_availability_code', 255)->nullable();
184  $table->string('technical_protection_code', 255)->nullable();
185  $table->string('returnable_indicator_code', 255)->nullable();
186  $table->string('remote_url', 2047)->nullable();
187  $table->string('url_path', 64)->nullable();
188  $table->smallInteger('is_approved')->default(0);
189  $table->smallInteger('is_available')->default(0);
190  $table->index(['submission_id'], 'publication_format_submission_id');
191  });
192 
193  // Publication Format metadata.
194  Capsule::schema()->create('publication_format_settings', function (Blueprint $table) {
195  $table->bigInteger('publication_format_id');
196  $table->string('locale', 14)->default('');
197  $table->string('setting_name', 255);
198  $table->text('setting_value')->nullable();
199  $table->string('setting_type', 6)->comment('(bool|int|float|string|object)');
200  $table->index(['publication_format_id'], 'publication_format_id_key');
201  $table->unique(['publication_format_id', 'locale', 'setting_name'], 'publication_format_settings_pkey');
202  });
203 
204  Capsule::schema()->create('submission_chapters', function (Blueprint $table) {
205  $table->bigInteger('chapter_id')->autoIncrement();
206  $table->bigInteger('primary_contact_id')->nullable();
207  $table->bigInteger('publication_id');
208  $table->float('seq', 8, 2)->default(0);
209  $table->index(['chapter_id'], 'chapters_chapter_id');
210  $table->index(['publication_id'], 'chapters_publication_id');
211  });
212 
213  // Language dependent monograph chapter metadata.
214  Capsule::schema()->create('submission_chapter_settings', function (Blueprint $table) {
215  $table->bigInteger('chapter_id');
216  $table->string('locale', 14)->default('');
217  $table->string('setting_name', 255);
218  $table->text('setting_value')->nullable();
219  $table->string('setting_type', 6)->comment('(bool|int|float|string|object)');
220  $table->index(['chapter_id'], 'submission_chapter_settings_chapter_id');
221  $table->unique(['chapter_id', 'locale', 'setting_name'], 'submission_chapter_settings_pkey');
222  });
223 
224  Capsule::schema()->create('submission_chapter_authors', function (Blueprint $table) {
225  $table->bigInteger('author_id');
226  $table->bigInteger('chapter_id');
227  $table->smallInteger('primary_contact')->default(0);
228  $table->float('seq', 8, 2)->default(0);
229  $table->unique(['author_id', 'chapter_id'], 'chapter_authors_pkey');
230  });
231 
232  // Presses and basic press settings.
233  Capsule::schema()->create('presses', function (Blueprint $table) {
234  $table->bigInteger('press_id')->autoIncrement();
235  $table->string('path', 32);
236  $table->float('seq', 8, 2)->default(0);
237  $table->string('primary_locale', 14);
238  $table->smallInteger('enabled')->default(1);
239  $table->unique(['path'], 'press_path');
240  });
241 
242  // Press settings.
243  Capsule::schema()->create('press_settings', function (Blueprint $table) {
244  $table->bigInteger('press_id');
245  $table->string('locale', 14)->default('');
246  $table->string('setting_name', 255);
247  $table->text('setting_value')->nullable();
248  $table->string('setting_type', 6)->nullable();
249  $table->index(['press_id'], 'press_settings_press_id');
250  $table->unique(['press_id', 'locale', 'setting_name'], 'press_settings_pkey');
251  });
252 
253  // Spotlights
254  Capsule::schema()->create('spotlights', function (Blueprint $table) {
255  $table->bigInteger('spotlight_id')->autoIncrement();
256  $table->smallInteger('assoc_type');
257  $table->smallInteger('assoc_id');
258  $table->bigInteger('press_id');
259  $table->index(['assoc_type', 'assoc_id'], 'spotlights_assoc');
260  });
261 
262  // Spotlight metadata.
263  Capsule::schema()->create('spotlight_settings', function (Blueprint $table) {
264  $table->bigInteger('spotlight_id');
265  $table->string('locale', 14)->default('');
266  $table->string('setting_name', 255);
267  $table->text('setting_value')->nullable();
268  $table->string('setting_type', 6)->comment('(bool|int|float|string|object|date)');
269  $table->index(['spotlight_id'], 'spotlight_settings_id');
270  $table->unique(['spotlight_id', 'locale', 'setting_name'], 'spotlight_settings_pkey');
271  });
272 
273  // Logs queued (unfulfilled) payments.
274  Capsule::schema()->create('queued_payments', function (Blueprint $table) {
275  $table->bigInteger('queued_payment_id')->autoIncrement();
276  $table->datetime('date_created');
277  $table->datetime('date_modified');
278  $table->date('expiry_date')->nullable();
279  $table->text('payment_data')->nullable();
280  });
281 
282  // Logs completed (fulfilled) payments.
283  Capsule::schema()->create('completed_payments', function (Blueprint $table) {
284  $table->bigInteger('completed_payment_id')->autoIncrement();
285  $table->datetime('timestamp');
286  $table->bigInteger('payment_type');
287  $table->bigInteger('context_id');
288  $table->bigInteger('user_id')->nullable();
289  // NOTE: assoc_id NOT numeric to incorporate file idents
290  $table->string('assoc_id', 16)->nullable();
291  $table->float('amount', 8, 2);
292  $table->string('currency_code_alpha', 3)->nullable();
293  $table->string('payment_method_plugin_name', 80)->nullable();
294  });
295  }
296 
301  public function down() {
302  Capsule::schema()->drop('completed_payments');
303  Capsule::schema()->drop('identification_codes');
304  Capsule::schema()->drop('publication_dates');
305  Capsule::schema()->drop('sales_rights');
306  Capsule::schema()->drop('markets');
307  Capsule::schema()->drop('representatives');
308  Capsule::schema()->drop('features');
309  Capsule::schema()->drop('new_releases');
310  Capsule::schema()->drop('series');
311  Capsule::schema()->drop('series_settings');
312  Capsule::schema()->drop('series_categories');
313  Capsule::schema()->drop('publications');
314  Capsule::schema()->drop('publication_formats');
315  Capsule::schema()->drop('publication_format_settings');
316  Capsule::schema()->drop('submission_chapters');
317  Capsule::schema()->drop('submission_chapter_settings');
318  Capsule::schema()->drop('submission_chapter_authors');
319  Capsule::schema()->drop('presses');
320  Capsule::schema()->drop('press_settings');
321  Capsule::schema()->drop('spotlights');
322  Capsule::schema()->drop('spotlight_settings');
323  Capsule::schema()->drop('queued_payments');
324  Capsule::schema()->drop('completed_payments');
325  }
326 }
OMPMigration\down
down()
Definition: OMPMigration.inc.php:301
OMPMigration\up
up()
Definition: OMPMigration.inc.php:24
OMPMigration
Describe database table structures.
Definition: OMPMigration.inc.php:19