2018-09-19 15:47:51 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
Poor man's migration system
|
|
|
|
*/
|
2018-09-19 18:01:27 +00:00
|
|
|
namespace migrations;
|
2018-09-19 15:47:51 +00:00
|
|
|
|
2018-09-22 11:54:39 +00:00
|
|
|
function get_previous_version() {
|
|
|
|
$previous_version = get_option( 'pterotype_previously_migrated_version' );
|
|
|
|
if ( !$previous_version ) {
|
|
|
|
$previous_version = '0.0.0';
|
|
|
|
}
|
|
|
|
return $previous_version;
|
2018-09-20 18:45:14 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 15:47:51 +00:00
|
|
|
/*
|
|
|
|
It's okay to add new queries to this function, but don't ever delete queries.
|
|
|
|
*/
|
|
|
|
function run_migrations() {
|
2018-09-22 11:54:39 +00:00
|
|
|
$previous_version = get_previous_version();
|
2018-09-19 17:46:40 +00:00
|
|
|
if ( version_compare( $previous_version, PTEROTYPE_VERSION, '>=' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2018-09-20 18:45:14 +00:00
|
|
|
apply_migration( '0.0.1', 'migration_0_0_1' );
|
|
|
|
apply_migration( '0.0.2', 'migration_0_0_2' );
|
2018-09-19 15:47:51 +00:00
|
|
|
update_option( 'pterotype_previously_migrated_version', PTEROTYPE_VERSION );
|
|
|
|
}
|
|
|
|
|
2018-09-20 18:45:14 +00:00
|
|
|
function apply_migration( $version, $migration_func ) {
|
2018-09-22 11:54:39 +00:00
|
|
|
$previous_version = get_previous_version();
|
2018-09-20 18:45:14 +00:00
|
|
|
if ( version_compare( $previous_version, $version, '<' ) ) {
|
|
|
|
call_user_func( __NAMESPACE__ . '\\' . $migration_func );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 15:47:51 +00:00
|
|
|
function migration_0_0_1() {
|
|
|
|
global $wpdb;
|
|
|
|
$wpdb->query(
|
|
|
|
"
|
2018-09-19 21:33:20 +00:00
|
|
|
CREATE TABLE pterotype_activities (
|
2018-09-19 15:47:51 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
activitypub_id VARCHAR(255) UNIQUE NOT NULL,
|
|
|
|
activity TEXT NOT NULL
|
|
|
|
)
|
|
|
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
"
|
|
|
|
);
|
|
|
|
$wpdb->query(
|
|
|
|
"
|
|
|
|
CREATE UNIQUE INDEX ACTIVITIES_ACTIVITYPUB_ID_INDEX
|
2018-09-19 21:33:20 +00:00
|
|
|
ON pterotype_activities (activitypub_id);
|
2018-09-19 15:47:51 +00:00
|
|
|
"
|
|
|
|
);
|
|
|
|
$wpdb->query(
|
|
|
|
"
|
2018-09-19 21:33:20 +00:00
|
|
|
CREATE TABLE pterotype_objects (
|
2018-09-19 15:47:51 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
activitypub_id VARCHAR(255) UNIQUE NOT NULL,
|
|
|
|
object TEXT NOT NULL
|
|
|
|
)
|
|
|
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
"
|
|
|
|
);
|
|
|
|
$wpdb->query(
|
|
|
|
"
|
|
|
|
CREATE UNIQUE INDEX OBJECT_ACTIVITYPUB_ID_INDEX
|
2018-09-19 21:33:20 +00:00
|
|
|
ON pterotype_objects (activitypub_id);
|
2018-09-19 15:47:51 +00:00
|
|
|
"
|
|
|
|
);
|
|
|
|
$wpdb->query(
|
|
|
|
"
|
2018-09-19 21:33:20 +00:00
|
|
|
CREATE TABLE pterotype_outbox (
|
2018-09-19 15:47:51 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
actor_id INT UNSIGNED NOT NULL,
|
|
|
|
activity_id INT UNSIGNED NOT NULL,
|
|
|
|
FOREIGN KEY outbox_activity_fk(activity_id)
|
2018-09-19 21:33:20 +00:00
|
|
|
REFERENCES pterotype_activities(id)
|
2018-09-19 15:47:51 +00:00
|
|
|
)
|
|
|
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
"
|
|
|
|
);
|
|
|
|
$wpdb->query(
|
|
|
|
"
|
2018-09-19 21:33:20 +00:00
|
|
|
CREATE TABLE pterotype_actors(
|
2018-09-19 15:47:51 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
slug VARCHAR(64) UNIQUE NOT NULL,
|
|
|
|
type VARCHAR(64) NOT NULL
|
|
|
|
)
|
|
|
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
"
|
|
|
|
);
|
|
|
|
$wpdb->query(
|
|
|
|
"
|
2018-09-19 21:33:20 +00:00
|
|
|
CREATE TABLE pterotype_likes (
|
2018-09-19 15:47:51 +00:00
|
|
|
actor_id INT UNSIGNED NOT NULL,
|
|
|
|
object_id INT UNSIGNED NOT NULL,
|
|
|
|
PRIMARY KEY (actor_id, object_id),
|
|
|
|
FOREIGN KEY likes_actor_fk(actor_id)
|
2018-09-19 21:33:20 +00:00
|
|
|
REFERENCES pterotype_actors(id),
|
2018-09-19 15:47:51 +00:00
|
|
|
FOREIGN KEY likes_object_fk(object_id)
|
2018-09-19 21:33:20 +00:00
|
|
|
REFERENCES pterotype_objects(id)
|
2018-09-19 15:47:51 +00:00
|
|
|
)
|
|
|
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
"
|
|
|
|
);
|
|
|
|
$wpdb->query(
|
|
|
|
"
|
2018-09-19 21:33:20 +00:00
|
|
|
CREATE TABLE pterotype_following(
|
2018-09-19 15:47:51 +00:00
|
|
|
actor_id INT UNSIGNED NOT NULL,
|
|
|
|
object_id INT UNSIGNED NOT NULL,
|
|
|
|
state VARCHAR(64) NOT NULL,
|
|
|
|
PRIMARY KEY (actor_id, object_id),
|
|
|
|
FOREIGN KEY following_actor_fk(actor_id)
|
2018-09-19 21:33:20 +00:00
|
|
|
REFERENCES pterotype_actors(id),
|
2018-09-19 15:47:51 +00:00
|
|
|
FOREIGN KEY following_object_fk(object_id)
|
2018-09-19 21:33:20 +00:00
|
|
|
REFERENCES pterotype_objects(id)
|
2018-09-19 15:47:51 +00:00
|
|
|
)
|
|
|
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
"
|
|
|
|
);
|
|
|
|
$wpdb->query(
|
|
|
|
"
|
2018-09-19 21:33:20 +00:00
|
|
|
CREATE TABLE pterotype_blocks(
|
2018-09-19 15:47:51 +00:00
|
|
|
actor_id INT UNSIGNED NOT NULL,
|
|
|
|
blocked_actor_url TEXT NOT NULL,
|
|
|
|
FOREIGN KEY blocks_actor_fk(actor_id)
|
2018-09-19 21:33:20 +00:00
|
|
|
REFERENCES pterotype_actors(id)
|
2018-09-19 15:47:51 +00:00
|
|
|
)
|
|
|
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
"
|
|
|
|
);
|
2018-09-19 21:43:59 +00:00
|
|
|
$wpdb->query(
|
|
|
|
"
|
|
|
|
CREATE TABLE pterotype_inbox (
|
|
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
actor_id INT UNSIGNED NOT NULL,
|
|
|
|
activity_id INT UNSIGNED NOT NULL,
|
|
|
|
FOREIGN KEY inbox_activity_fk(activity_id)
|
|
|
|
REFERENCES pterotype_activities(id)
|
|
|
|
)
|
|
|
|
ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
"
|
|
|
|
);
|
2018-09-19 15:47:51 +00:00
|
|
|
}
|
2018-09-20 18:45:14 +00:00
|
|
|
|
|
|
|
function migration_0_0_2() {
|
|
|
|
global $wpdb;
|
|
|
|
$wpdb->query(
|
|
|
|
"
|
|
|
|
ALTER TABLE pterotype_objects
|
|
|
|
MODIFY object JSON NOT NULL,
|
|
|
|
ADD type VARCHAR(50) NOT NULL;
|
|
|
|
"
|
|
|
|
);
|
|
|
|
$wpdb->query(
|
|
|
|
"
|
|
|
|
ALTER TABLE pterotype_activities
|
|
|
|
MODIFY activity JSON NOT NULL,
|
|
|
|
ADD type VARCHAR(50) NOT NULL;
|
|
|
|
"
|
|
|
|
);
|
|
|
|
}
|
2018-09-19 15:47:51 +00:00
|
|
|
?>
|