Skip to content

Commit 0c5efdd

Browse files
Utilize migration classes
1 parent a4fbbe3 commit 0c5efdd

File tree

1 file changed

+3
-84
lines changed

1 file changed

+3
-84
lines changed

bluem-db.php

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -21,90 +21,9 @@ function bluem_db_create_requests_table(): void {
2121

2222
include_once ABSPATH . 'wp-admin/includes/upgrade.php';
2323

24-
// Define table names
25-
$table_name_storage = $wpdb->prefix . 'bluem_storage';
26-
$table_name_requests = $wpdb->prefix . 'bluem_requests';
27-
$table_name_links = $wpdb->prefix . 'bluem_requests_links';
28-
$table_name_logs = $wpdb->prefix . 'bluem_requests_log';
29-
30-
/**
31-
* Create tables.
32-
*/
33-
$sql = "CREATE TABLE IF NOT EXISTS `$table_name_requests` (
34-
id mediumint(9) NOT NULL AUTO_INCREMENT,
35-
user_id mediumint(9) NOT NULL,
36-
transaction_id varchar(64) NOT NULL,
37-
entrance_code varchar(64) NOT NULL,
38-
transaction_url varchar(256) NOT NULL,
39-
timestamp timestamp DEFAULT NOW() NOT NULL,
40-
description tinytext NOT NULL,
41-
debtor_reference varchar(64) NOT NULL,
42-
type varchar(16) DEFAULT '' NOT NULL,
43-
status varchar(16) DEFAULT 'created' NOT NULL,
44-
order_id mediumint(9) DEFAULT NULL,
45-
payload text NOT NULL,
46-
PRIMARY KEY (id)
47-
) $charset_collate;";
48-
dbDelta( $sql );
49-
50-
$sql = "CREATE TABLE IF NOT EXISTS `$table_name_logs` (
51-
id mediumint(9) NOT NULL AUTO_INCREMENT,
52-
request_id mediumint(9) NOT NULL,
53-
timestamp timestamp DEFAULT NOW() NOT NULL,
54-
description varchar(512) NOT NULL,
55-
user_id mediumint(9) NULL,
56-
PRIMARY KEY (id)
57-
) $charset_collate;";
58-
dbDelta( $sql );
59-
60-
$sql = "CREATE TABLE IF NOT EXISTS `$table_name_links` (
61-
id mediumint(9) NOT NULL AUTO_INCREMENT,
62-
request_id mediumint(9) NOT NULL,
63-
item_id mediumint(9) NOT NULL,
64-
item_type varchar(32) NOT NULL DEFAULT 'order',
65-
timestamp timestamp DEFAULT NOW() NOT NULL,
66-
PRIMARY KEY (id)
67-
) $charset_collate;";
68-
dbDelta( $sql );
69-
70-
$sql = "CREATE TABLE IF NOT EXISTS `$table_name_storage` (
71-
id mediumint(9) NOT NULL AUTO_INCREMENT,
72-
token varchar(191) NOT NULL,
73-
secret varchar(191) NOT NULL,
74-
data longtext NOT NULL,
75-
timestamp timestamp DEFAULT NOW() NOT NULL,
76-
PRIMARY KEY (id)
77-
) $charset_collate;";
78-
dbDelta( $sql );
79-
80-
// Check for previous installed versions
81-
if ( !empty( $installed_ver ) )
82-
{
83-
/**
84-
* Migrate old tables to new tables including wp-prefix.
85-
* Old tables in release version <= 1.3.
86-
*/
87-
if ( $installed_ver <= '1.3' )
88-
{
89-
$bluem_requests_table_exists = $wpdb->get_var("SHOW TABLES LIKE 'bluem_requests'") === 'bluem_requests';
90-
$bluem_requests_links_table_exists = $wpdb->get_var("SHOW TABLES LIKE 'bluem_requests_log'") === 'bluem_requests_log';
91-
$bluem_requests_log_table_exists = $wpdb->get_var("SHOW TABLES LIKE 'bluem_requests_links'") === 'bluem_requests_links';
92-
93-
if ( $bluem_requests_table_exists ) {
94-
$sql = "INSERT INTO `$table_name_requests` SELECT * FROM bluem_requests;";
95-
dbDelta( $sql );
96-
}
97-
98-
if ( $bluem_requests_log_table_exists ) {
99-
$sql = "INSERT INTO `$table_name_logs` SELECT * FROM bluem_requests_log;";
100-
dbDelta( $sql );
101-
}
102-
103-
if ( $bluem_requests_links_table_exists ) {
104-
$sql = "INSERT INTO `$table_name_links` SELECT * FROM bluem_requests_links;";
105-
dbDelta( $sql );
106-
}
107-
}
24+
$migrationRepository = new DatabaseMigrationRepository();
25+
foreach($migrationRepository->getMigrations($installed_ver) as $migration) {
26+
dbDelta($migration->sql);
10827
}
10928

11029
update_option(

0 commit comments

Comments
 (0)