From be707960fbb896a59617bbbaf6072ba24fc703ac Mon Sep 17 00:00:00 2001 From: James Clark Date: Wed, 1 Jul 2020 02:55:15 +0100 Subject: [PATCH 1/2] Rename mysql migrations --- ..._users.down.sql => 20171026211738_create_users.mysql.down.sql} | 0 ...eate_users.up.sql => 20171026211738_create_users.mysql.up.sql} | 0 ...es.down.sql => 20171026211808_create_instances.mysql.down.sql} | 0 ...tances.up.sql => 20171026211808_create_instances.mysql.up.sql} | 0 ...wn.sql => 20171026211834_create_refresh_tokens.mysql.down.sql} | 0 ...s.up.sql => 20171026211834_create_refresh_tokens.mysql.up.sql} | 0 ....down.sql => 20180103212743_json_user_metadata.mysql.down.sql} | 0 ...data.up.sql => 20180103212743_json_user_metadata.mysql.up.sql} | 0 ...sql => 20180108183307_drop_instance_deleted_at.mysql.down.sql} | 0 ...p.sql => 20180108183307_drop_instance_deleted_at.mysql.up.sql} | 0 ...sql => 20180119214651_create_audit_log_entries.mysql.down.sql} | 0 ...p.sql => 20180119214651_create_audit_log_entries.mysql.up.sql} | 0 ...> 20180125194653_add_refresh_tokens_updated_at.mysql.down.sql} | 0 ... => 20180125194653_add_refresh_tokens_updated_at.mysql.up.sql} | 0 14 files changed, 0 insertions(+), 0 deletions(-) rename migrations/{20171026211738_create_users.down.sql => 20171026211738_create_users.mysql.down.sql} (100%) rename migrations/{20171026211738_create_users.up.sql => 20171026211738_create_users.mysql.up.sql} (100%) rename migrations/{20171026211808_create_instances.down.sql => 20171026211808_create_instances.mysql.down.sql} (100%) rename migrations/{20171026211808_create_instances.up.sql => 20171026211808_create_instances.mysql.up.sql} (100%) rename migrations/{20171026211834_create_refresh_tokens.down.sql => 20171026211834_create_refresh_tokens.mysql.down.sql} (100%) rename migrations/{20171026211834_create_refresh_tokens.up.sql => 20171026211834_create_refresh_tokens.mysql.up.sql} (100%) rename migrations/{20180103212743_json_user_metadata.down.sql => 20180103212743_json_user_metadata.mysql.down.sql} (100%) rename migrations/{20180103212743_json_user_metadata.up.sql => 20180103212743_json_user_metadata.mysql.up.sql} (100%) rename migrations/{20180108183307_drop_instance_deleted_at.down.sql => 20180108183307_drop_instance_deleted_at.mysql.down.sql} (100%) rename migrations/{20180108183307_drop_instance_deleted_at.up.sql => 20180108183307_drop_instance_deleted_at.mysql.up.sql} (100%) rename migrations/{20180119214651_create_audit_log_entries.down.sql => 20180119214651_create_audit_log_entries.mysql.down.sql} (100%) rename migrations/{20180119214651_create_audit_log_entries.up.sql => 20180119214651_create_audit_log_entries.mysql.up.sql} (100%) rename migrations/{20180125194653_add_refresh_tokens_updated_at.down.sql => 20180125194653_add_refresh_tokens_updated_at.mysql.down.sql} (100%) rename migrations/{20180125194653_add_refresh_tokens_updated_at.up.sql => 20180125194653_add_refresh_tokens_updated_at.mysql.up.sql} (100%) diff --git a/migrations/20171026211738_create_users.down.sql b/migrations/20171026211738_create_users.mysql.down.sql similarity index 100% rename from migrations/20171026211738_create_users.down.sql rename to migrations/20171026211738_create_users.mysql.down.sql diff --git a/migrations/20171026211738_create_users.up.sql b/migrations/20171026211738_create_users.mysql.up.sql similarity index 100% rename from migrations/20171026211738_create_users.up.sql rename to migrations/20171026211738_create_users.mysql.up.sql diff --git a/migrations/20171026211808_create_instances.down.sql b/migrations/20171026211808_create_instances.mysql.down.sql similarity index 100% rename from migrations/20171026211808_create_instances.down.sql rename to migrations/20171026211808_create_instances.mysql.down.sql diff --git a/migrations/20171026211808_create_instances.up.sql b/migrations/20171026211808_create_instances.mysql.up.sql similarity index 100% rename from migrations/20171026211808_create_instances.up.sql rename to migrations/20171026211808_create_instances.mysql.up.sql diff --git a/migrations/20171026211834_create_refresh_tokens.down.sql b/migrations/20171026211834_create_refresh_tokens.mysql.down.sql similarity index 100% rename from migrations/20171026211834_create_refresh_tokens.down.sql rename to migrations/20171026211834_create_refresh_tokens.mysql.down.sql diff --git a/migrations/20171026211834_create_refresh_tokens.up.sql b/migrations/20171026211834_create_refresh_tokens.mysql.up.sql similarity index 100% rename from migrations/20171026211834_create_refresh_tokens.up.sql rename to migrations/20171026211834_create_refresh_tokens.mysql.up.sql diff --git a/migrations/20180103212743_json_user_metadata.down.sql b/migrations/20180103212743_json_user_metadata.mysql.down.sql similarity index 100% rename from migrations/20180103212743_json_user_metadata.down.sql rename to migrations/20180103212743_json_user_metadata.mysql.down.sql diff --git a/migrations/20180103212743_json_user_metadata.up.sql b/migrations/20180103212743_json_user_metadata.mysql.up.sql similarity index 100% rename from migrations/20180103212743_json_user_metadata.up.sql rename to migrations/20180103212743_json_user_metadata.mysql.up.sql diff --git a/migrations/20180108183307_drop_instance_deleted_at.down.sql b/migrations/20180108183307_drop_instance_deleted_at.mysql.down.sql similarity index 100% rename from migrations/20180108183307_drop_instance_deleted_at.down.sql rename to migrations/20180108183307_drop_instance_deleted_at.mysql.down.sql diff --git a/migrations/20180108183307_drop_instance_deleted_at.up.sql b/migrations/20180108183307_drop_instance_deleted_at.mysql.up.sql similarity index 100% rename from migrations/20180108183307_drop_instance_deleted_at.up.sql rename to migrations/20180108183307_drop_instance_deleted_at.mysql.up.sql diff --git a/migrations/20180119214651_create_audit_log_entries.down.sql b/migrations/20180119214651_create_audit_log_entries.mysql.down.sql similarity index 100% rename from migrations/20180119214651_create_audit_log_entries.down.sql rename to migrations/20180119214651_create_audit_log_entries.mysql.down.sql diff --git a/migrations/20180119214651_create_audit_log_entries.up.sql b/migrations/20180119214651_create_audit_log_entries.mysql.up.sql similarity index 100% rename from migrations/20180119214651_create_audit_log_entries.up.sql rename to migrations/20180119214651_create_audit_log_entries.mysql.up.sql diff --git a/migrations/20180125194653_add_refresh_tokens_updated_at.down.sql b/migrations/20180125194653_add_refresh_tokens_updated_at.mysql.down.sql similarity index 100% rename from migrations/20180125194653_add_refresh_tokens_updated_at.down.sql rename to migrations/20180125194653_add_refresh_tokens_updated_at.mysql.down.sql diff --git a/migrations/20180125194653_add_refresh_tokens_updated_at.up.sql b/migrations/20180125194653_add_refresh_tokens_updated_at.mysql.up.sql similarity index 100% rename from migrations/20180125194653_add_refresh_tokens_updated_at.up.sql rename to migrations/20180125194653_add_refresh_tokens_updated_at.mysql.up.sql From 6816ba940488e6fdf51d060f577dc5d2d2990a9e Mon Sep 17 00:00:00 2001 From: James Clark Date: Wed, 1 Jul 2020 02:55:45 +0100 Subject: [PATCH 2/2] Add Postgresql migrations --- ...71026211738_create_users.postgres.down.sql | 1 + ...0171026211738_create_users.postgres.up.sql | 25 +++++++++++++++++++ ...6211808_create_instances.postgres.down.sql | 1 + ...026211808_create_instances.postgres.up.sql | 8 ++++++ ...34_create_refresh_tokens.postgres.down.sql | 1 + ...1834_create_refresh_tokens.postgres.up.sql | 12 +++++++++ ...12743_json_user_metadata.postgres.down.sql | 3 +++ ...3212743_json_user_metadata.postgres.up.sql | 6 +++++ ...drop_instance_deleted_at.postgres.down.sql | 1 + ...7_drop_instance_deleted_at.postgres.up.sql | 1 + ...create_audit_log_entries.postgres.down.sql | 1 + ...1_create_audit_log_entries.postgres.up.sql | 8 ++++++ ...efresh_tokens_updated_at.postgres.down.sql | 1 + ..._refresh_tokens_updated_at.postgres.up.sql | 2 ++ 14 files changed, 71 insertions(+) create mode 100644 migrations/20171026211738_create_users.postgres.down.sql create mode 100644 migrations/20171026211738_create_users.postgres.up.sql create mode 100644 migrations/20171026211808_create_instances.postgres.down.sql create mode 100644 migrations/20171026211808_create_instances.postgres.up.sql create mode 100644 migrations/20171026211834_create_refresh_tokens.postgres.down.sql create mode 100644 migrations/20171026211834_create_refresh_tokens.postgres.up.sql create mode 100644 migrations/20180103212743_json_user_metadata.postgres.down.sql create mode 100644 migrations/20180103212743_json_user_metadata.postgres.up.sql create mode 100644 migrations/20180108183307_drop_instance_deleted_at.postgres.down.sql create mode 100644 migrations/20180108183307_drop_instance_deleted_at.postgres.up.sql create mode 100644 migrations/20180119214651_create_audit_log_entries.postgres.down.sql create mode 100644 migrations/20180119214651_create_audit_log_entries.postgres.up.sql create mode 100644 migrations/20180125194653_add_refresh_tokens_updated_at.postgres.down.sql create mode 100644 migrations/20180125194653_add_refresh_tokens_updated_at.postgres.up.sql diff --git a/migrations/20171026211738_create_users.postgres.down.sql b/migrations/20171026211738_create_users.postgres.down.sql new file mode 100644 index 000000000..34e2a91f8 --- /dev/null +++ b/migrations/20171026211738_create_users.postgres.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS {{ index .Options "Namespace" }}users; diff --git a/migrations/20171026211738_create_users.postgres.up.sql b/migrations/20171026211738_create_users.postgres.up.sql new file mode 100644 index 000000000..2d20a08a5 --- /dev/null +++ b/migrations/20171026211738_create_users.postgres.up.sql @@ -0,0 +1,25 @@ +CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}users ( + instance_id uuid, + id uuid PRIMARY KEY, + aud character varying(255), + role character varying(255), + email character varying(255), + encrypted_password character varying(255), + confirmed_at timestamp with time zone, + invited_at timestamp with time zone, + confirmation_token character varying(255), + confirmation_sent_at timestamp with time zone, + recovery_token character varying(255), + recovery_sent_at timestamp with time zone, + email_change_token character varying(255), + email_change character varying(255), + email_change_sent_at timestamp with time zone, + last_sign_in_at timestamp with time zone, + raw_app_meta_data text, + raw_user_meta_data text, + is_super_admin boolean, + created_at timestamp with time zone, + updated_at timestamp with time zone +); +CREATE INDEX users_instance_id_idx ON {{ index .Options "Namespace" }}users USING btree (instance_id); +CREATE INDEX users_instance_id_email_idx ON {{ index .Options "Namespace" }}users USING btree (instance_id, email); diff --git a/migrations/20171026211808_create_instances.postgres.down.sql b/migrations/20171026211808_create_instances.postgres.down.sql new file mode 100644 index 000000000..5ce947b86 --- /dev/null +++ b/migrations/20171026211808_create_instances.postgres.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS {{ index .Options "Namespace" }}instances; diff --git a/migrations/20171026211808_create_instances.postgres.up.sql b/migrations/20171026211808_create_instances.postgres.up.sql new file mode 100644 index 000000000..6afe771c9 --- /dev/null +++ b/migrations/20171026211808_create_instances.postgres.up.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}instances ( + id uuid PRIMARY KEY, + uuid uuid, + raw_base_config text, + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone +); diff --git a/migrations/20171026211834_create_refresh_tokens.postgres.down.sql b/migrations/20171026211834_create_refresh_tokens.postgres.down.sql new file mode 100644 index 000000000..0281ab929 --- /dev/null +++ b/migrations/20171026211834_create_refresh_tokens.postgres.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS {{ index .Options "Namespace" }}refresh_tokens; diff --git a/migrations/20171026211834_create_refresh_tokens.postgres.up.sql b/migrations/20171026211834_create_refresh_tokens.postgres.up.sql new file mode 100644 index 000000000..7b2fa72a6 --- /dev/null +++ b/migrations/20171026211834_create_refresh_tokens.postgres.up.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}refresh_tokens ( + instance_id uuid, + id bigserial PRIMARY KEY, + token character varying(255), + user_id character varying(255), + revoked boolean, + created_at timestamp with time zone +); + +CREATE INDEX refresh_tokens_instance_id_idx ON {{ index .Options "Namespace" }}refresh_tokens USING btree (instance_id); +CREATE INDEX refresh_tokens_instance_id_user_id_idx ON {{ index .Options "Namespace" }}refresh_tokens USING btree (instance_id, user_id); +CREATE INDEX refresh_tokens_token_idx ON {{ index .Options "Namespace" }}refresh_tokens USING btree (token); diff --git a/migrations/20180103212743_json_user_metadata.postgres.down.sql b/migrations/20180103212743_json_user_metadata.postgres.down.sql new file mode 100644 index 000000000..6305e18d7 --- /dev/null +++ b/migrations/20180103212743_json_user_metadata.postgres.down.sql @@ -0,0 +1,3 @@ +ALTER TABLE {{ index .Options "Namespace" }}users +ALTER raw_app_meta_data TYPE text USING raw_app_meta_data #>> '{}', +ALTER raw_user_meta_data TYPE text USING raw_user_meta_data #>> '{}'; diff --git a/migrations/20180103212743_json_user_metadata.postgres.up.sql b/migrations/20180103212743_json_user_metadata.postgres.up.sql new file mode 100644 index 000000000..2e6253644 --- /dev/null +++ b/migrations/20180103212743_json_user_metadata.postgres.up.sql @@ -0,0 +1,6 @@ +UPDATE {{ index .Options "Namespace" }}users SET raw_app_meta_data = '{}' WHERE raw_app_meta_data = ''; +UPDATE {{ index .Options "Namespace" }}users SET raw_user_meta_data = '{}' WHERE raw_user_meta_data = ''; + +ALTER TABLE {{ index .Options "Namespace" }}users +ALTER raw_app_meta_data TYPE JSONB USING raw_app_meta_data::JSONB, +ALTER raw_user_meta_data TYPE JSONB USING raw_user_meta_data::JSONB; diff --git a/migrations/20180108183307_drop_instance_deleted_at.postgres.down.sql b/migrations/20180108183307_drop_instance_deleted_at.postgres.down.sql new file mode 100644 index 000000000..dd6cfd662 --- /dev/null +++ b/migrations/20180108183307_drop_instance_deleted_at.postgres.down.sql @@ -0,0 +1 @@ +ALTER TABLE {{ index .Options "Namespace" }}instances ADD deleted_at timestamp with time zone; diff --git a/migrations/20180108183307_drop_instance_deleted_at.postgres.up.sql b/migrations/20180108183307_drop_instance_deleted_at.postgres.up.sql new file mode 100644 index 000000000..7851e5241 --- /dev/null +++ b/migrations/20180108183307_drop_instance_deleted_at.postgres.up.sql @@ -0,0 +1 @@ +ALTER TABLE {{ index .Options "Namespace" }}instances DROP deleted_at; diff --git a/migrations/20180119214651_create_audit_log_entries.postgres.down.sql b/migrations/20180119214651_create_audit_log_entries.postgres.down.sql new file mode 100644 index 000000000..f7d97105e --- /dev/null +++ b/migrations/20180119214651_create_audit_log_entries.postgres.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS {{ index .Options "Namespace" }}audit_log_entries; \ No newline at end of file diff --git a/migrations/20180119214651_create_audit_log_entries.postgres.up.sql b/migrations/20180119214651_create_audit_log_entries.postgres.up.sql new file mode 100644 index 000000000..709856a4a --- /dev/null +++ b/migrations/20180119214651_create_audit_log_entries.postgres.up.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}audit_log_entries ( + instance_id uuid, + id uuid PRIMARY KEY, + payload json, + created_at timestamp with time zone +); + +CREATE INDEX audit_logs_instance_id_idx ON {{ index .Options "Namespace" }}audit_log_entries USING btree (instance_id); diff --git a/migrations/20180125194653_add_refresh_tokens_updated_at.postgres.down.sql b/migrations/20180125194653_add_refresh_tokens_updated_at.postgres.down.sql new file mode 100644 index 000000000..fa3699dfa --- /dev/null +++ b/migrations/20180125194653_add_refresh_tokens_updated_at.postgres.down.sql @@ -0,0 +1 @@ +ALTER TABLE {{ index .Options "Namespace" }}refresh_tokens DROP updated_at; \ No newline at end of file diff --git a/migrations/20180125194653_add_refresh_tokens_updated_at.postgres.up.sql b/migrations/20180125194653_add_refresh_tokens_updated_at.postgres.up.sql new file mode 100644 index 000000000..6cf2f60dd --- /dev/null +++ b/migrations/20180125194653_add_refresh_tokens_updated_at.postgres.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE {{ index .Options "Namespace" }}refresh_tokens ADD updated_at timestamp with time zone DEFAULT NULL; +UPDATE {{ index .Options "Namespace" }}refresh_tokens SET updated_at = created_at;