about summary refs log tree commit diff
path: root/db/migrate
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2020-06-02 19:24:53 +0200
committerGitHub <noreply@github.com>2020-06-02 19:24:53 +0200
commit5d8398c8b8b51ee7363e7d45acc560f489783e34 (patch)
tree1e0b663049feafdc003ad3c01b25bf5d5d793402 /db/migrate
parent9b7e3b4774d47c184aa759364d41f40e0cdfa210 (diff)
Add E2EE API (#13820)
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20170129000348_create_devices.rb13
-rw-r--r--db/migrate/20170205175257_remove_devices.rb2
-rw-r--r--db/migrate/20200516180352_create_devices.rb14
-rw-r--r--db/migrate/20200516183822_create_one_time_keys.rb12
-rw-r--r--db/migrate/20200518083523_create_encrypted_messages.rb15
-rw-r--r--db/migrate/20200521180606_encrypted_message_ids_to_timestamp_ids.rb13
-rw-r--r--db/migrate/20200529214050_add_devices_url_to_accounts.rb5
-rw-r--r--db/migrate/20200601222558_create_system_keys.rb9
8 files changed, 69 insertions, 14 deletions
diff --git a/db/migrate/20170129000348_create_devices.rb b/db/migrate/20170129000348_create_devices.rb
deleted file mode 100644
index bf8f5fc6e..000000000
--- a/db/migrate/20170129000348_create_devices.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-class CreateDevices < ActiveRecord::Migration[5.0]
-  def change
-    create_table :devices do |t|
-      t.integer :account_id, null: false
-      t.string :registration_id, null: false, default: ''
-
-      t.timestamps
-    end
-
-    add_index :devices, :registration_id
-    add_index :devices, :account_id
-  end
-end
diff --git a/db/migrate/20170205175257_remove_devices.rb b/db/migrate/20170205175257_remove_devices.rb
index e96ffed4d..9ef5c440e 100644
--- a/db/migrate/20170205175257_remove_devices.rb
+++ b/db/migrate/20170205175257_remove_devices.rb
@@ -1,5 +1,5 @@
 class RemoveDevices < ActiveRecord::Migration[5.0]
   def change
-    drop_table :devices
+    drop_table :devices if table_exists?(:devices)
   end
 end
diff --git a/db/migrate/20200516180352_create_devices.rb b/db/migrate/20200516180352_create_devices.rb
new file mode 100644
index 000000000..04a628a89
--- /dev/null
+++ b/db/migrate/20200516180352_create_devices.rb
@@ -0,0 +1,14 @@
+class CreateDevices < ActiveRecord::Migration[5.2]
+  def change
+    create_table :devices do |t|
+      t.references :access_token, foreign_key: { to_table: :oauth_access_tokens, on_delete: :cascade, index: :unique }
+      t.references :account, foreign_key: { on_delete: :cascade }
+      t.string :device_id, default: '', null: false
+      t.string :name, default: '', null: false
+      t.text :fingerprint_key, default: '', null: false
+      t.text :identity_key, default: '', null: false
+
+      t.timestamps
+    end
+  end
+end
diff --git a/db/migrate/20200516183822_create_one_time_keys.rb b/db/migrate/20200516183822_create_one_time_keys.rb
new file mode 100644
index 000000000..642b9e632
--- /dev/null
+++ b/db/migrate/20200516183822_create_one_time_keys.rb
@@ -0,0 +1,12 @@
+class CreateOneTimeKeys < ActiveRecord::Migration[5.2]
+  def change
+    create_table :one_time_keys do |t|
+      t.references :device, foreign_key: { on_delete: :cascade }
+      t.string :key_id, default: '', null: false, index: :unique
+      t.text :key, default: '', null: false
+      t.text :signature, default: '', null: false
+
+      t.timestamps
+    end
+  end
+end
diff --git a/db/migrate/20200518083523_create_encrypted_messages.rb b/db/migrate/20200518083523_create_encrypted_messages.rb
new file mode 100644
index 000000000..486726303
--- /dev/null
+++ b/db/migrate/20200518083523_create_encrypted_messages.rb
@@ -0,0 +1,15 @@
+class CreateEncryptedMessages < ActiveRecord::Migration[5.2]
+  def change
+    create_table :encrypted_messages do |t|
+      t.references :device, foreign_key: { on_delete: :cascade }
+      t.references :from_account, foreign_key: { to_table: :accounts, on_delete: :cascade }
+      t.string :from_device_id, default: '', null: false
+      t.integer :type, default: 0, null: false
+      t.text :body, default: '', null: false
+      t.text :digest, default: '', null: false
+      t.text :message_franking, default: '', null: false
+
+      t.timestamps
+    end
+  end
+end
diff --git a/db/migrate/20200521180606_encrypted_message_ids_to_timestamp_ids.rb b/db/migrate/20200521180606_encrypted_message_ids_to_timestamp_ids.rb
new file mode 100644
index 000000000..24d43a0bf
--- /dev/null
+++ b/db/migrate/20200521180606_encrypted_message_ids_to_timestamp_ids.rb
@@ -0,0 +1,13 @@
+class EncryptedMessageIdsToTimestampIds < ActiveRecord::Migration[5.2]
+  def up
+    safety_assured do
+      execute("ALTER TABLE encrypted_messages ALTER COLUMN id SET DEFAULT timestamp_id('encrypted_messages')")
+    end
+  end
+
+  def down
+    execute("LOCK encrypted_messages")
+    execute("SELECT setval('encrypted_messages_id_seq', (SELECT MAX(id) FROM encrypted_messages))")
+    execute("ALTER TABLE encrypted_messages ALTER COLUMN id SET DEFAULT nextval('encrypted_messages_id_seq')")
+  end
+end
diff --git a/db/migrate/20200529214050_add_devices_url_to_accounts.rb b/db/migrate/20200529214050_add_devices_url_to_accounts.rb
new file mode 100644
index 000000000..564877e5d
--- /dev/null
+++ b/db/migrate/20200529214050_add_devices_url_to_accounts.rb
@@ -0,0 +1,5 @@
+class AddDevicesUrlToAccounts < ActiveRecord::Migration[5.2]
+  def change
+    add_column :accounts, :devices_url, :string
+  end
+end
diff --git a/db/migrate/20200601222558_create_system_keys.rb b/db/migrate/20200601222558_create_system_keys.rb
new file mode 100644
index 000000000..fd9d221aa
--- /dev/null
+++ b/db/migrate/20200601222558_create_system_keys.rb
@@ -0,0 +1,9 @@
+class CreateSystemKeys < ActiveRecord::Migration[5.2]
+  def change
+    create_table :system_keys do |t|
+      t.binary :key
+
+      t.timestamps
+    end
+  end
+end