Open Journal Systems  3.3.0
CommonMigration.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 CommonMigration extends Migration {
24  public function up() {
25  // Describes the installation and upgrade version history for the application and all installed plugins.
26  Capsule::schema()->create('versions', function (Blueprint $table) {
27  $table->integer('major')->default(0)->comment('Major component of version number, e.g. the 2 in OJS 2.3.8-0');
28  $table->integer('minor')->default(0)->comment('Minor component of version number, e.g. the 3 in OJS 2.3.8-0');
29  $table->integer('revision')->default(0)->comment('Revision component of version number, e.g. the 8 in OJS 2.3.8-0');
30  $table->integer('build')->default(0)->comment('Build component of version number, e.g. the 0 in OJS 2.3.8-0');
31  $table->datetime('date_installed');
32  $table->smallInteger('current')->default(0)->comment('1 iff the version entry being described is currently active. This permits the table to store past installation history for forensic purposes.');
33  $table->string('product_type', 30)->comment('Describes the type of product this row describes, e.g. "plugins.generic" (for a generic plugin) or "core" for the application itelf')->nullable();
34  $table->string('product', 30)->comment('Uniquely identifies the product this version row describes, e.g. "ojs2" for OJS 2.x, "languageToggle" for the language toggle block plugin, etc.')->nullable();
35  $table->string('product_class_name', 80)->comment('Specifies the class name associated with this product, for plugins, or the empty string where not applicable.')->nullable();
36  $table->smallInteger('lazy_load')->default(0)->comment('1 iff the row describes a lazy-load plugin; 0 otherwise');
37  $table->smallInteger('sitewide')->default(0)->comment('1 iff the row describes a site-wide plugin; 0 otherwise');
38  $table->unique(['product_type', 'product', 'major', 'minor', 'revision', 'build'], 'versions_pkey');
39  });
40 
41  // Common site settings.
42  Capsule::schema()->create('site', function (Blueprint $table) {
43  $table->bigInteger('redirect')->default(0)->comment('If not 0, redirect to the specified journal/conference/... site.');
44  $table->string('primary_locale', 14)->comment('Primary locale for the site.');
45  $table->smallInteger('min_password_length')->default(6);
46  $table->string('installed_locales', 1024)->default('en_US')->comment('Locales for which support has been installed.');
47  $table->string('supported_locales', 1024)->comment('Locales supported by the site (for hosted journals/conferences/...).')->nullable();
48  $table->string('original_style_file_name', 255)->nullable();
49  });
50 
51  // Site settings.
52  Capsule::schema()->create('site_settings', function (Blueprint $table) {
53  $table->string('setting_name', 255);
54  $table->string('locale', 14)->default('');
55  $table->text('setting_value')->nullable();
56  $table->unique(['setting_name', 'locale'], 'site_settings_pkey');
57  });
58 
59  // User authentication sources.
60  Capsule::schema()->create('auth_sources', function (Blueprint $table) {
61  $table->bigInteger('auth_id')->autoIncrement();
62  $table->string('title', 60);
63  $table->string('plugin', 32);
64  $table->smallInteger('auth_default')->default(0);
65  $table->text('settings')->nullable();
66  });
67 
68  // User authentication credentials and profile data.
69  Capsule::schema()->create('users', function (Blueprint $table) {
70  $table->bigInteger('user_id')->autoIncrement();
71  $table->string('username', 32);
72  $table->string('password', 255);
73  $table->string('email', 255);
74  $table->string('url', 2047)->nullable();
75  $table->string('phone', 32)->nullable();
76  $table->string('mailing_address', 255)->nullable();
77  $table->string('billing_address', 255)->nullable();
78  $table->string('country', 90)->nullable();
79  $table->string('locales', 255)->nullable();
80  $table->text('gossip')->nullable();
81  $table->datetime('date_last_email')->nullable();
82  $table->datetime('date_registered');
83  $table->datetime('date_validated')->nullable();
84  $table->datetime('date_last_login');
85  $table->smallInteger('must_change_password')->nullable();
86  $table->bigInteger('auth_id')->nullable();
87  $table->string('auth_str', 255)->nullable();
88  $table->smallInteger('disabled')->default(0);
89  $table->text('disabled_reason')->nullable();
90  $table->smallInteger('inline_help')->nullable();
91  $table->unique(['username'], 'users_username');
92  $table->unique(['email'], 'users_email');
93  });
94 
95  // Locale-specific user data
96  Capsule::schema()->create('user_settings', function (Blueprint $table) {
97  $table->bigInteger('user_id');
98  $table->string('locale', 14)->default('');
99  $table->string('setting_name', 255);
100  $table->bigInteger('assoc_type')->default(0);
101  $table->bigInteger('assoc_id')->default(0);
102  $table->text('setting_value')->nullable();
103  $table->string('setting_type', 6);
104  $table->index(['user_id'], 'user_settings_user_id');
105  $table->unique(['user_id', 'locale', 'setting_name', 'assoc_type', 'assoc_id'], 'user_settings_pkey');
106  $table->index(['setting_name', 'locale'], 'user_settings_locale_setting_name_index');
107  });
108 
109  // Browser/user sessions and session data.
110  Capsule::schema()->create('sessions', function (Blueprint $table) {
111  $table->string('session_id', 128);
112  $table->bigInteger('user_id')->nullable();
113  $table->string('ip_address', 39);
114  $table->string('user_agent', 255)->nullable();
115  $table->bigInteger('created')->default(0);
116  $table->bigInteger('last_used')->default(0);
117  $table->smallInteger('remember')->default(0);
118  $table->text('data');
119  $table->string('domain', 255)->nullable();
120  $table->index(['user_id'], 'sessions_user_id');
121  $table->unique(['session_id'], 'sessions_pkey');
122  });
123 
124  // Access keys are used to provide pseudo-login functionality for security-minimal tasks. Passkeys can be emailed directly to users, who can use them for a limited time in lieu of standard username and password.
125  Capsule::schema()->create('access_keys', function (Blueprint $table) {
126  $table->bigInteger('access_key_id')->autoIncrement();
127  $table->string('context', 40);
128  $table->string('key_hash', 40);
129  $table->bigInteger('user_id');
130  $table->bigInteger('assoc_id')->nullable();
131  $table->datetime('expiry_date');
132  $table->index(['key_hash', 'user_id', 'context'], 'access_keys_hash');
133  });
134 
135  // Stores notifications for users as created by the system after certain operations.
136  Capsule::schema()->create('notifications', function (Blueprint $table) {
137  $table->bigInteger('notification_id')->autoIncrement();
138  $table->bigInteger('context_id');
139  $table->bigInteger('user_id')->nullable();
140  $table->bigInteger('level');
141  $table->bigInteger('type');
142  $table->datetime('date_created');
143  $table->datetime('date_read')->nullable();
144  $table->bigInteger('assoc_type')->nullable();
145  $table->bigInteger('assoc_id')->nullable();
146  $table->index(['context_id', 'user_id', 'level'], 'notifications_context_id_user_id');
147  $table->index(['context_id', 'level'], 'notifications_context_id');
148  $table->index(['assoc_type', 'assoc_id'], 'notifications_assoc');
149  $table->index(['user_id', 'level'], 'notifications_user_id_level');
150  });
151 
152  // Stores metadata for specific notifications
153  Capsule::schema()->create('notification_settings', function (Blueprint $table) {
154  $table->bigInteger('notification_id');
155  $table->string('locale', 14)->nullable();
156  $table->string('setting_name', 64);
157  $table->text('setting_value');
158  $table->string('setting_type', 6)->comment('(bool|int|float|string|object)');
159  $table->unique(['notification_id', 'locale', 'setting_name'], 'notification_settings_pkey');
160  });
161 
162  // Stores user preferences on what notifications should be blocked and/or emailed to them
163  Capsule::schema()->create('notification_subscription_settings', function (Blueprint $table) {
164  $table->bigInteger('setting_id')->autoIncrement();
165  $table->string('setting_name', 64);
166  $table->text('setting_value');
167  $table->bigInteger('user_id');
168  $table->bigInteger('context');
169  $table->string('setting_type', 6)->comment('(bool|int|float|string|object)');
170  });
171 
172  // Stores subscriptions to the notification mailing list
173  Capsule::schema()->create('notification_mail_list', function (Blueprint $table) {
174  $table->bigInteger('notification_mail_list_id')->autoIncrement();
175  $table->string('email', 90);
176  $table->smallInteger('confirmed')->default(0);
177  $table->string('token', 40);
178  $table->bigInteger('context');
179  $table->unique(['email', 'context'], 'notification_mail_list_email_context');
180  });
181 
182  // Default email templates.
183  Capsule::schema()->create('email_templates_default', function (Blueprint $table) {
184  $table->bigInteger('email_id')->autoIncrement();
185  $table->string('email_key', 64)->comment('Unique identifier for this email.');
186  $table->smallInteger('can_disable')->default(0);
187  $table->smallInteger('can_edit')->default(0);
188  $table->bigInteger('from_role_id')->nullable();
189  $table->bigInteger('to_role_id')->nullable();
190  $table->bigInteger('stage_id')->nullable();
191  $table->index(['email_key'], 'email_templates_default_email_key');
192  });
193 
194  // Default data for email templates.
195  Capsule::schema()->create('email_templates_default_data', function (Blueprint $table) {
196  $table->string('email_key', 64)->comment('Unique identifier for this email.');
197  $table->string('locale', 14)->default('en_US');
198  $table->string('subject', 120);
199  $table->text('body')->nullable();
200  $table->text('description')->nullable();
201  $table->unique(['email_key', 'locale'], 'email_templates_default_data_pkey');
202  });
203 
204  // Templates for emails.
205  Capsule::schema()->create('email_templates', function (Blueprint $table) {
206  $table->bigInteger('email_id')->autoIncrement();
207  $table->string('email_key', 64)->comment('Unique identifier for this email.');
208  $table->bigInteger('context_id');
209  $table->smallInteger('enabled')->default(1);
210  $table->unique(['email_key', 'context_id'], 'email_templates_email_key');
211  });
212 
213  Capsule::schema()->create('email_templates_settings', function (Blueprint $table) {
214  $table->bigInteger('email_id');
215  $table->string('locale', 14)->default('');
216  $table->string('setting_name', 255);
217  $table->text('setting_value')->nullable();
218  $table->index(['email_id'], 'email_settings_email_id');
219  $table->unique(['email_id', 'locale', 'setting_name'], 'email_settings_pkey');
220  });
221 
222  // Resumption tokens for the OAI protocol interface.
223  Capsule::schema()->create('oai_resumption_tokens', function (Blueprint $table) {
224  $table->string('token', 32);
225  $table->bigInteger('expire');
226  $table->integer('record_offset');
227  $table->text('params')->nullable();
228  $table->unique(['token'], 'oai_resumption_tokens_pkey');
229  });
230 
231  // Plugin settings.
232  Capsule::schema()->create('plugin_settings', function (Blueprint $table) {
233  $table->string('plugin_name', 80);
234  $table->bigInteger('context_id');
235  $table->string('setting_name', 80);
236  $table->text('setting_value')->nullable();
237  $table->string('setting_type', 6)->comment('(bool|int|float|string|object)');
238  $table->index(['plugin_name'], 'plugin_settings_plugin_name');
239  $table->unique(['plugin_name', 'context_id', 'setting_name'], 'plugin_settings_pkey');
240  });
241 
242  }
243 
248  public function down() {
249  Capsule::schema()->drop('plugin_settings');
250  Capsule::schema()->drop('oai_resumption_tokens');
251  Capsule::schema()->drop('email_templates_settings');
252  Capsule::schema()->drop('email_templates');
253  Capsule::schema()->drop('email_templates_default_data');
254  Capsule::schema()->drop('email_templates_default');
255  Capsule::schema()->drop('notification_mail_list');
256  Capsule::schema()->drop('notification_subscription_settings');
257  Capsule::schema()->drop('notification_settings');
258  Capsule::schema()->drop('notifications');
259  Capsule::schema()->drop('access_keys');
260  Capsule::schema()->drop('sessions');
261  Capsule::schema()->drop('user_settings');
262  Capsule::schema()->drop('users');
263  Capsule::schema()->drop('auth_sources');
264  Capsule::schema()->drop('site_settings');
265  Capsule::schema()->drop('site');
266  Capsule::schema()->drop('versions');
267  }
268 }
CommonMigration\up
up()
Definition: CommonMigration.inc.php:24
CommonMigration
Describe database table structures.
Definition: CommonMigration.inc.php:19
CommonMigration\down
down()
Definition: CommonMigration.inc.php:248