aboutsummaryrefslogtreecommitdiff
path: root/migrations
diff options
context:
space:
mode:
authorNils Domrose <[email protected]>2019-05-26 23:02:41 +0200
committerNils Domrose <[email protected]>2019-05-26 23:03:05 +0200
commitff759397f6742781a722dab029d695c4bbcf794a (patch)
tree525c5ef8fd704e8fb95b423369bd5bfcc59cc564 /migrations
parentbadd22ac3d1b6c364c7be59e64ec0c48f2b960dd (diff)
downloadvaultwarden-ff759397f6742781a722dab029d695c4bbcf794a.tar.gz
vaultwarden-ff759397f6742781a722dab029d695c4bbcf794a.zip
initial mysql support
Diffstat (limited to 'migrations')
-rw-r--r--migrations/mysql/2018-01-14-171611_create_tables/down.sql (renamed from migrations/2018-01-14-171611_create_tables/down.sql)0
-rw-r--r--migrations/mysql/2018-01-14-171611_create_tables/up.sql (renamed from migrations/2018-01-14-171611_create_tables/up.sql)6
-rw-r--r--migrations/mysql/2018-02-17-205753_create_collections_and_orgs/down.sql (renamed from migrations/2018-02-17-205753_create_collections_and_orgs/down.sql)0
-rw-r--r--migrations/mysql/2018-02-17-205753_create_collections_and_orgs/up.sql (renamed from migrations/2018-02-17-205753_create_collections_and_orgs/up.sql)4
-rw-r--r--migrations/mysql/2018-04-27-155151_create_users_ciphers/down.sql (renamed from migrations/2018-04-27-155151_create_users_ciphers/down.sql)0
-rw-r--r--migrations/mysql/2018-04-27-155151_create_users_ciphers/up.sql (renamed from migrations/2018-04-27-155151_create_users_ciphers/up.sql)6
-rw-r--r--migrations/mysql/2018-05-08-161616_create_collection_cipher_map/down.sql (renamed from migrations/2018-05-08-161616_create_collection_cipher_map/down.sql)0
-rw-r--r--migrations/mysql/2018-05-08-161616_create_collection_cipher_map/up.sql (renamed from migrations/2018-05-08-161616_create_collection_cipher_map/up.sql)0
-rw-r--r--migrations/mysql/2018-05-25-232323_update_attachments_reference/down.sql (renamed from migrations/2018-05-25-232323_update_attachments_reference/down.sql)0
-rw-r--r--migrations/mysql/2018-05-25-232323_update_attachments_reference/up.sql (renamed from migrations/2018-05-25-232323_update_attachments_reference/up.sql)0
-rw-r--r--migrations/mysql/2018-06-01-112529_update_devices_twofactor_remember/down.sql (renamed from migrations/2018-06-01-112529_update_devices_twofactor_remember/down.sql)0
-rw-r--r--migrations/mysql/2018-06-01-112529_update_devices_twofactor_remember/up.sql (renamed from migrations/2018-06-01-112529_update_devices_twofactor_remember/up.sql)0
-rw-r--r--migrations/mysql/2018-07-11-181453_create_u2f_twofactor/down.sql (renamed from migrations/2018-07-11-181453_create_u2f_twofactor/down.sql)0
-rw-r--r--migrations/mysql/2018-07-11-181453_create_u2f_twofactor/up.sql (renamed from migrations/2018-07-11-181453_create_u2f_twofactor/up.sql)6
-rw-r--r--migrations/mysql/2018-08-27-172114_update_ciphers/down.sql (renamed from migrations/2018-08-27-172114_update_ciphers/down.sql)0
-rw-r--r--migrations/mysql/2018-08-27-172114_update_ciphers/up.sql (renamed from migrations/2018-08-27-172114_update_ciphers/up.sql)0
-rw-r--r--migrations/mysql/2018-09-10-111213_add_invites/down.sql (renamed from migrations/2018-09-10-111213_add_invites/down.sql)0
-rw-r--r--migrations/mysql/2018-09-10-111213_add_invites/up.sql (renamed from migrations/2018-09-10-111213_add_invites/up.sql)0
-rw-r--r--migrations/mysql/2018-09-19-144557_add_kdf_columns/down.sql (renamed from migrations/2018-09-19-144557_add_kdf_columns/down.sql)0
-rw-r--r--migrations/mysql/2018-09-19-144557_add_kdf_columns/up.sql (renamed from migrations/2018-09-19-144557_add_kdf_columns/up.sql)0
-rw-r--r--migrations/mysql/2018-11-27-152651_add_att_key_columns/down.sql (renamed from migrations/2018-11-27-152651_add_att_key_columns/down.sql)0
-rw-r--r--migrations/mysql/2018-11-27-152651_add_att_key_columns/up.sql3
-rw-r--r--migrations/mysql/2019-05-26-216651_rename_key_and_type_columns/down.sql7
-rw-r--r--migrations/mysql/2019-05-26-216651_rename_key_and_type_columns/up.sql7
-rw-r--r--migrations/sqlite/2018-01-14-171611_create_tables/down.sql9
-rw-r--r--migrations/sqlite/2018-01-14-171611_create_tables/up.sql62
-rw-r--r--migrations/sqlite/2018-02-17-205753_create_collections_and_orgs/down.sql8
-rw-r--r--migrations/sqlite/2018-02-17-205753_create_collections_and_orgs/up.sql31
-rw-r--r--migrations/sqlite/2018-04-27-155151_create_users_ciphers/down.sql0
-rw-r--r--migrations/sqlite/2018-04-27-155151_create_users_ciphers/up.sql34
-rw-r--r--migrations/sqlite/2018-05-08-161616_create_collection_cipher_map/down.sql1
-rw-r--r--migrations/sqlite/2018-05-08-161616_create_collection_cipher_map/up.sql5
-rw-r--r--migrations/sqlite/2018-05-25-232323_update_attachments_reference/down.sql0
-rw-r--r--migrations/sqlite/2018-05-25-232323_update_attachments_reference/up.sql14
-rw-r--r--migrations/sqlite/2018-06-01-112529_update_devices_twofactor_remember/down.sql1
-rw-r--r--migrations/sqlite/2018-06-01-112529_update_devices_twofactor_remember/up.sql3
-rw-r--r--migrations/sqlite/2018-07-11-181453_create_u2f_twofactor/down.sql8
-rw-r--r--migrations/sqlite/2018-07-11-181453_create_u2f_twofactor/up.sql15
-rw-r--r--migrations/sqlite/2018-08-27-172114_update_ciphers/down.sql0
-rw-r--r--migrations/sqlite/2018-08-27-172114_update_ciphers/up.sql3
-rw-r--r--migrations/sqlite/2018-09-10-111213_add_invites/down.sql1
-rw-r--r--migrations/sqlite/2018-09-10-111213_add_invites/up.sql3
-rw-r--r--migrations/sqlite/2018-09-19-144557_add_kdf_columns/down.sql0
-rw-r--r--migrations/sqlite/2018-09-19-144557_add_kdf_columns/up.sql7
-rw-r--r--migrations/sqlite/2018-11-27-152651_add_att_key_columns/down.sql0
-rw-r--r--migrations/sqlite/2018-11-27-152651_add_att_key_columns/up.sql (renamed from migrations/2018-11-27-152651_add_att_key_columns/up.sql)2
-rw-r--r--migrations/sqlite/2019-05-26-216651_rename_key_and_type_columns/down.sql7
-rw-r--r--migrations/sqlite/2019-05-26-216651_rename_key_and_type_columns/up.sql7
48 files changed, 248 insertions, 12 deletions
diff --git a/migrations/2018-01-14-171611_create_tables/down.sql b/migrations/mysql/2018-01-14-171611_create_tables/down.sql
index 1025a2c0..1025a2c0 100644
--- a/migrations/2018-01-14-171611_create_tables/down.sql
+++ b/migrations/mysql/2018-01-14-171611_create_tables/down.sql
diff --git a/migrations/2018-01-14-171611_create_tables/up.sql b/migrations/mysql/2018-01-14-171611_create_tables/up.sql
index 0a1fc8c9..244c3c80 100644
--- a/migrations/2018-01-14-171611_create_tables/up.sql
+++ b/migrations/mysql/2018-01-14-171611_create_tables/up.sql
@@ -8,7 +8,7 @@ CREATE TABLE users (
salt BLOB NOT NULL,
password_iterations INTEGER NOT NULL,
password_hint TEXT,
- akey TEXT NOT NULL,
+ `key` TEXT NOT NULL,
private_key TEXT,
public_key TEXT,
totp_secret TEXT,
@@ -24,7 +24,7 @@ CREATE TABLE devices (
updated_at DATETIME NOT NULL,
user_uuid VARCHAR(40) NOT NULL REFERENCES users (uuid),
name TEXT NOT NULL,
- atype INTEGER NOT NULL,
+ type INTEGER NOT NULL,
push_token TEXT,
refresh_token TEXT NOT NULL
);
@@ -36,7 +36,7 @@ CREATE TABLE ciphers (
user_uuid VARCHAR(40) NOT NULL REFERENCES users (uuid),
folder_uuid VARCHAR(40) REFERENCES folders (uuid),
organization_uuid VARCHAR(40),
- atype INTEGER NOT NULL,
+ type INTEGER NOT NULL,
name TEXT NOT NULL,
notes TEXT,
fields TEXT,
diff --git a/migrations/2018-02-17-205753_create_collections_and_orgs/down.sql b/migrations/mysql/2018-02-17-205753_create_collections_and_orgs/down.sql
index b6446cd8..b6446cd8 100644
--- a/migrations/2018-02-17-205753_create_collections_and_orgs/down.sql
+++ b/migrations/mysql/2018-02-17-205753_create_collections_and_orgs/down.sql
diff --git a/migrations/2018-02-17-205753_create_collections_and_orgs/up.sql b/migrations/mysql/2018-02-17-205753_create_collections_and_orgs/up.sql
index 8d5508ff..c5200a76 100644
--- a/migrations/2018-02-17-205753_create_collections_and_orgs/up.sql
+++ b/migrations/mysql/2018-02-17-205753_create_collections_and_orgs/up.sql
@@ -22,9 +22,9 @@ CREATE TABLE users_organizations (
org_uuid VARCHAR(40) NOT NULL REFERENCES organizations (uuid),
access_all BOOLEAN NOT NULL,
- akey TEXT NOT NULL,
+ `key` TEXT NOT NULL,
status INTEGER NOT NULL,
- atype INTEGER NOT NULL,
+ type INTEGER NOT NULL,
UNIQUE (user_uuid, org_uuid)
);
diff --git a/migrations/2018-04-27-155151_create_users_ciphers/down.sql b/migrations/mysql/2018-04-27-155151_create_users_ciphers/down.sql
index e69de29b..e69de29b 100644
--- a/migrations/2018-04-27-155151_create_users_ciphers/down.sql
+++ b/migrations/mysql/2018-04-27-155151_create_users_ciphers/down.sql
diff --git a/migrations/2018-04-27-155151_create_users_ciphers/up.sql b/migrations/mysql/2018-04-27-155151_create_users_ciphers/up.sql
index 00989e4a..65c53d54 100644
--- a/migrations/2018-04-27-155151_create_users_ciphers/up.sql
+++ b/migrations/mysql/2018-04-27-155151_create_users_ciphers/up.sql
@@ -7,7 +7,7 @@ CREATE TABLE ciphers (
user_uuid VARCHAR(40) REFERENCES users (uuid), -- Make this optional
organization_uuid VARCHAR(40) REFERENCES organizations (uuid), -- Add reference to orgs table
-- Remove folder_uuid
- atype INTEGER NOT NULL,
+ type INTEGER NOT NULL,
name TEXT NOT NULL,
notes TEXT,
fields TEXT,
@@ -22,8 +22,8 @@ CREATE TABLE folders_ciphers (
PRIMARY KEY (cipher_uuid, folder_uuid)
);
-INSERT INTO ciphers (uuid, created_at, updated_at, user_uuid, organization_uuid, atype, name, notes, fields, data, favorite)
-SELECT uuid, created_at, updated_at, user_uuid, organization_uuid, atype, name, notes, fields, data, favorite FROM oldCiphers;
+INSERT INTO ciphers (uuid, created_at, updated_at, user_uuid, organization_uuid, type, name, notes, fields, data, favorite)
+SELECT uuid, created_at, updated_at, user_uuid, organization_uuid, type, name, notes, fields, data, favorite FROM oldCiphers;
INSERT INTO folders_ciphers (cipher_uuid, folder_uuid)
SELECT uuid, folder_uuid FROM oldCiphers WHERE folder_uuid IS NOT NULL;
diff --git a/migrations/2018-05-08-161616_create_collection_cipher_map/down.sql b/migrations/mysql/2018-05-08-161616_create_collection_cipher_map/down.sql
index ba973f4f..ba973f4f 100644
--- a/migrations/2018-05-08-161616_create_collection_cipher_map/down.sql
+++ b/migrations/mysql/2018-05-08-161616_create_collection_cipher_map/down.sql
diff --git a/migrations/2018-05-08-161616_create_collection_cipher_map/up.sql b/migrations/mysql/2018-05-08-161616_create_collection_cipher_map/up.sql
index fe407be1..fe407be1 100644
--- a/migrations/2018-05-08-161616_create_collection_cipher_map/up.sql
+++ b/migrations/mysql/2018-05-08-161616_create_collection_cipher_map/up.sql
diff --git a/migrations/2018-05-25-232323_update_attachments_reference/down.sql b/migrations/mysql/2018-05-25-232323_update_attachments_reference/down.sql
index e69de29b..e69de29b 100644
--- a/migrations/2018-05-25-232323_update_attachments_reference/down.sql
+++ b/migrations/mysql/2018-05-25-232323_update_attachments_reference/down.sql
diff --git a/migrations/2018-05-25-232323_update_attachments_reference/up.sql b/migrations/mysql/2018-05-25-232323_update_attachments_reference/up.sql
index eef50768..eef50768 100644
--- a/migrations/2018-05-25-232323_update_attachments_reference/up.sql
+++ b/migrations/mysql/2018-05-25-232323_update_attachments_reference/up.sql
diff --git a/migrations/2018-06-01-112529_update_devices_twofactor_remember/down.sql b/migrations/mysql/2018-06-01-112529_update_devices_twofactor_remember/down.sql
index 291a97c5..291a97c5 100644
--- a/migrations/2018-06-01-112529_update_devices_twofactor_remember/down.sql
+++ b/migrations/mysql/2018-06-01-112529_update_devices_twofactor_remember/down.sql
diff --git a/migrations/2018-06-01-112529_update_devices_twofactor_remember/up.sql b/migrations/mysql/2018-06-01-112529_update_devices_twofactor_remember/up.sql
index aaad8eab..aaad8eab 100644
--- a/migrations/2018-06-01-112529_update_devices_twofactor_remember/up.sql
+++ b/migrations/mysql/2018-06-01-112529_update_devices_twofactor_remember/up.sql
diff --git a/migrations/2018-07-11-181453_create_u2f_twofactor/down.sql b/migrations/mysql/2018-07-11-181453_create_u2f_twofactor/down.sql
index 84b6ee63..84b6ee63 100644
--- a/migrations/2018-07-11-181453_create_u2f_twofactor/down.sql
+++ b/migrations/mysql/2018-07-11-181453_create_u2f_twofactor/down.sql
diff --git a/migrations/2018-07-11-181453_create_u2f_twofactor/up.sql b/migrations/mysql/2018-07-11-181453_create_u2f_twofactor/up.sql
index 7da3a51b..4fd57175 100644
--- a/migrations/2018-07-11-181453_create_u2f_twofactor/up.sql
+++ b/migrations/mysql/2018-07-11-181453_create_u2f_twofactor/up.sql
@@ -1,15 +1,15 @@
CREATE TABLE twofactor (
uuid VARCHAR(40) NOT NULL PRIMARY KEY,
user_uuid VARCHAR(40) NOT NULL REFERENCES users (uuid),
- atype INTEGER NOT NULL,
+ type INTEGER NOT NULL,
enabled BOOLEAN NOT NULL,
data TEXT NOT NULL,
- UNIQUE (user_uuid, atype)
+ UNIQUE (user_uuid, type)
);
-INSERT INTO twofactor (uuid, user_uuid, atype, enabled, data)
+INSERT INTO twofactor (uuid, user_uuid, type, enabled, data)
SELECT UUID(), uuid, 0, 1, u.totp_secret FROM users u where u.totp_secret IS NOT NULL;
UPDATE users SET totp_secret = NULL; -- Instead of recreating the table, just leave the columns empty
diff --git a/migrations/2018-08-27-172114_update_ciphers/down.sql b/migrations/mysql/2018-08-27-172114_update_ciphers/down.sql
index e69de29b..e69de29b 100644
--- a/migrations/2018-08-27-172114_update_ciphers/down.sql
+++ b/migrations/mysql/2018-08-27-172114_update_ciphers/down.sql
diff --git a/migrations/2018-08-27-172114_update_ciphers/up.sql b/migrations/mysql/2018-08-27-172114_update_ciphers/up.sql
index 624efd66..624efd66 100644
--- a/migrations/2018-08-27-172114_update_ciphers/up.sql
+++ b/migrations/mysql/2018-08-27-172114_update_ciphers/up.sql
diff --git a/migrations/2018-09-10-111213_add_invites/down.sql b/migrations/mysql/2018-09-10-111213_add_invites/down.sql
index af3776cf..af3776cf 100644
--- a/migrations/2018-09-10-111213_add_invites/down.sql
+++ b/migrations/mysql/2018-09-10-111213_add_invites/down.sql
diff --git a/migrations/2018-09-10-111213_add_invites/up.sql b/migrations/mysql/2018-09-10-111213_add_invites/up.sql
index 4245aa82..4245aa82 100644
--- a/migrations/2018-09-10-111213_add_invites/up.sql
+++ b/migrations/mysql/2018-09-10-111213_add_invites/up.sql
diff --git a/migrations/2018-09-19-144557_add_kdf_columns/down.sql b/migrations/mysql/2018-09-19-144557_add_kdf_columns/down.sql
index e69de29b..e69de29b 100644
--- a/migrations/2018-09-19-144557_add_kdf_columns/down.sql
+++ b/migrations/mysql/2018-09-19-144557_add_kdf_columns/down.sql
diff --git a/migrations/2018-09-19-144557_add_kdf_columns/up.sql b/migrations/mysql/2018-09-19-144557_add_kdf_columns/up.sql
index bd98f40e..bd98f40e 100644
--- a/migrations/2018-09-19-144557_add_kdf_columns/up.sql
+++ b/migrations/mysql/2018-09-19-144557_add_kdf_columns/up.sql
diff --git a/migrations/2018-11-27-152651_add_att_key_columns/down.sql b/migrations/mysql/2018-11-27-152651_add_att_key_columns/down.sql
index e69de29b..e69de29b 100644
--- a/migrations/2018-11-27-152651_add_att_key_columns/down.sql
+++ b/migrations/mysql/2018-11-27-152651_add_att_key_columns/down.sql
diff --git a/migrations/mysql/2018-11-27-152651_add_att_key_columns/up.sql b/migrations/mysql/2018-11-27-152651_add_att_key_columns/up.sql
new file mode 100644
index 00000000..e77599fc
--- /dev/null
+++ b/migrations/mysql/2018-11-27-152651_add_att_key_columns/up.sql
@@ -0,0 +1,3 @@
+ALTER TABLE attachments
+ ADD COLUMN
+ `key` TEXT;
diff --git a/migrations/mysql/2019-05-26-216651_rename_key_and_type_columns/down.sql b/migrations/mysql/2019-05-26-216651_rename_key_and_type_columns/down.sql
new file mode 100644
index 00000000..8a87d193
--- /dev/null
+++ b/migrations/mysql/2019-05-26-216651_rename_key_and_type_columns/down.sql
@@ -0,0 +1,7 @@
+ALTER TABLE attachments CHANGE COLUMN akey `key` TEXT;
+ALTER TABLE ciphers CHANGE COLUMN atype type INTEGER NOT NULL;
+ALTER TABLE devices CHANGE COLUMN atype type INTEGER NOT NULL;
+ALTER TABLE twofactor CHANGE COLUMN atype type INTEGER NOT NULL;
+ALTER TABLE users CHANGE COLUMN akey `key` TEXT;
+ALTER TABLE users_organizations CHANGE COLUMN akey `key` TEXT;
+ALTER TABLE users_organizations CHANGE COLUMN atype type INTEGER NOT NULL; \ No newline at end of file
diff --git a/migrations/mysql/2019-05-26-216651_rename_key_and_type_columns/up.sql b/migrations/mysql/2019-05-26-216651_rename_key_and_type_columns/up.sql
new file mode 100644
index 00000000..cee0351e
--- /dev/null
+++ b/migrations/mysql/2019-05-26-216651_rename_key_and_type_columns/up.sql
@@ -0,0 +1,7 @@
+ALTER TABLE attachments CHANGE COLUMN `key` akey TEXT;
+ALTER TABLE ciphers CHANGE COLUMN type atype INTEGER NOT NULL;
+ALTER TABLE devices CHANGE COLUMN type atype INTEGER NOT NULL;
+ALTER TABLE twofactor CHANGE COLUMN type atype INTEGER NOT NULL;
+ALTER TABLE users CHANGE COLUMN `key` akey TEXT;
+ALTER TABLE users_organizations CHANGE COLUMN `key` akey TEXT;
+ALTER TABLE users_organizations CHANGE COLUMN type atype INTEGER NOT NULL; \ No newline at end of file
diff --git a/migrations/sqlite/2018-01-14-171611_create_tables/down.sql b/migrations/sqlite/2018-01-14-171611_create_tables/down.sql
new file mode 100644
index 00000000..1025a2c0
--- /dev/null
+++ b/migrations/sqlite/2018-01-14-171611_create_tables/down.sql
@@ -0,0 +1,9 @@
+DROP TABLE users;
+
+DROP TABLE devices;
+
+DROP TABLE ciphers;
+
+DROP TABLE attachments;
+
+DROP TABLE folders; \ No newline at end of file
diff --git a/migrations/sqlite/2018-01-14-171611_create_tables/up.sql b/migrations/sqlite/2018-01-14-171611_create_tables/up.sql
new file mode 100644
index 00000000..263ed8f3
--- /dev/null
+++ b/migrations/sqlite/2018-01-14-171611_create_tables/up.sql
@@ -0,0 +1,62 @@
+CREATE TABLE users (
+ uuid TEXT NOT NULL PRIMARY KEY,
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME NOT NULL,
+ email TEXT NOT NULL UNIQUE,
+ name TEXT NOT NULL,
+ password_hash BLOB NOT NULL,
+ salt BLOB NOT NULL,
+ password_iterations INTEGER NOT NULL,
+ password_hint TEXT,
+ key TEXT NOT NULL,
+ private_key TEXT,
+ public_key TEXT,
+ totp_secret TEXT,
+ totp_recover TEXT,
+ security_stamp TEXT NOT NULL,
+ equivalent_domains TEXT NOT NULL,
+ excluded_globals TEXT NOT NULL
+);
+
+CREATE TABLE devices (
+ uuid TEXT NOT NULL PRIMARY KEY,
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME NOT NULL,
+ user_uuid TEXT NOT NULL REFERENCES users (uuid),
+ name TEXT NOT NULL,
+ type INTEGER NOT NULL,
+ push_token TEXT,
+ refresh_token TEXT NOT NULL
+);
+
+CREATE TABLE ciphers (
+ uuid TEXT NOT NULL PRIMARY KEY,
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME NOT NULL,
+ user_uuid TEXT NOT NULL REFERENCES users (uuid),
+ folder_uuid TEXT REFERENCES folders (uuid),
+ organization_uuid TEXT,
+ type INTEGER NOT NULL,
+ name TEXT NOT NULL,
+ notes TEXT,
+ fields TEXT,
+ data TEXT NOT NULL,
+ favorite BOOLEAN NOT NULL
+);
+
+CREATE TABLE attachments (
+ id TEXT NOT NULL PRIMARY KEY,
+ cipher_uuid TEXT NOT NULL REFERENCES ciphers (uuid),
+ file_name TEXT NOT NULL,
+ file_size INTEGER NOT NULL
+
+);
+
+CREATE TABLE folders (
+ uuid TEXT NOT NULL PRIMARY KEY,
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME NOT NULL,
+ user_uuid TEXT NOT NULL REFERENCES users (uuid),
+ name TEXT NOT NULL
+);
+ \ No newline at end of file
diff --git a/migrations/sqlite/2018-02-17-205753_create_collections_and_orgs/down.sql b/migrations/sqlite/2018-02-17-205753_create_collections_and_orgs/down.sql
new file mode 100644
index 00000000..b6446cd8
--- /dev/null
+++ b/migrations/sqlite/2018-02-17-205753_create_collections_and_orgs/down.sql
@@ -0,0 +1,8 @@
+DROP TABLE collections;
+
+DROP TABLE organizations;
+
+
+DROP TABLE users_collections;
+
+DROP TABLE users_organizations;
diff --git a/migrations/sqlite/2018-02-17-205753_create_collections_and_orgs/up.sql b/migrations/sqlite/2018-02-17-205753_create_collections_and_orgs/up.sql
new file mode 100644
index 00000000..29601a4a
--- /dev/null
+++ b/migrations/sqlite/2018-02-17-205753_create_collections_and_orgs/up.sql
@@ -0,0 +1,31 @@
+CREATE TABLE collections (
+ uuid TEXT NOT NULL PRIMARY KEY,
+ org_uuid TEXT NOT NULL REFERENCES organizations (uuid),
+ name TEXT NOT NULL
+);
+
+CREATE TABLE organizations (
+ uuid TEXT NOT NULL PRIMARY KEY,
+ name TEXT NOT NULL,
+ billing_email TEXT NOT NULL
+);
+
+
+CREATE TABLE users_collections (
+ user_uuid TEXT NOT NULL REFERENCES users (uuid),
+ collection_uuid TEXT NOT NULL REFERENCES collections (uuid),
+ PRIMARY KEY (user_uuid, collection_uuid)
+);
+
+CREATE TABLE users_organizations (
+ uuid TEXT NOT NULL PRIMARY KEY,
+ user_uuid TEXT NOT NULL REFERENCES users (uuid),
+ org_uuid TEXT NOT NULL REFERENCES organizations (uuid),
+
+ access_all BOOLEAN NOT NULL,
+ key TEXT NOT NULL,
+ status INTEGER NOT NULL,
+ type INTEGER NOT NULL,
+
+ UNIQUE (user_uuid, org_uuid)
+);
diff --git a/migrations/sqlite/2018-04-27-155151_create_users_ciphers/down.sql b/migrations/sqlite/2018-04-27-155151_create_users_ciphers/down.sql
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/migrations/sqlite/2018-04-27-155151_create_users_ciphers/down.sql
diff --git a/migrations/sqlite/2018-04-27-155151_create_users_ciphers/up.sql b/migrations/sqlite/2018-04-27-155151_create_users_ciphers/up.sql
new file mode 100644
index 00000000..747f9e29
--- /dev/null
+++ b/migrations/sqlite/2018-04-27-155151_create_users_ciphers/up.sql
@@ -0,0 +1,34 @@
+ALTER TABLE ciphers RENAME TO oldCiphers;
+
+CREATE TABLE ciphers (
+ uuid TEXT NOT NULL PRIMARY KEY,
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME NOT NULL,
+ user_uuid TEXT REFERENCES users (uuid), -- Make this optional
+ organization_uuid TEXT REFERENCES organizations (uuid), -- Add reference to orgs table
+ -- Remove folder_uuid
+ type INTEGER NOT NULL,
+ name TEXT NOT NULL,
+ notes TEXT,
+ fields TEXT,
+ data TEXT NOT NULL,
+ favorite BOOLEAN NOT NULL
+);
+
+CREATE TABLE folders_ciphers (
+ cipher_uuid TEXT NOT NULL REFERENCES ciphers (uuid),
+ folder_uuid TEXT NOT NULL REFERENCES folders (uuid),
+
+ PRIMARY KEY (cipher_uuid, folder_uuid)
+);
+
+INSERT INTO ciphers (uuid, created_at, updated_at, user_uuid, organization_uuid, type, name, notes, fields, data, favorite)
+SELECT uuid, created_at, updated_at, user_uuid, organization_uuid, type, name, notes, fields, data, favorite FROM oldCiphers;
+
+INSERT INTO folders_ciphers (cipher_uuid, folder_uuid)
+SELECT uuid, folder_uuid FROM oldCiphers WHERE folder_uuid IS NOT NULL;
+
+
+DROP TABLE oldCiphers;
+
+ALTER TABLE users_collections ADD COLUMN read_only BOOLEAN NOT NULL DEFAULT 0; -- False
diff --git a/migrations/sqlite/2018-05-08-161616_create_collection_cipher_map/down.sql b/migrations/sqlite/2018-05-08-161616_create_collection_cipher_map/down.sql
new file mode 100644
index 00000000..ba973f4f
--- /dev/null
+++ b/migrations/sqlite/2018-05-08-161616_create_collection_cipher_map/down.sql
@@ -0,0 +1 @@
+DROP TABLE ciphers_collections; \ No newline at end of file
diff --git a/migrations/sqlite/2018-05-08-161616_create_collection_cipher_map/up.sql b/migrations/sqlite/2018-05-08-161616_create_collection_cipher_map/up.sql
new file mode 100644
index 00000000..9fdd7066
--- /dev/null
+++ b/migrations/sqlite/2018-05-08-161616_create_collection_cipher_map/up.sql
@@ -0,0 +1,5 @@
+CREATE TABLE ciphers_collections (
+ cipher_uuid TEXT NOT NULL REFERENCES ciphers (uuid),
+ collection_uuid TEXT NOT NULL REFERENCES collections (uuid),
+ PRIMARY KEY (cipher_uuid, collection_uuid)
+); \ No newline at end of file
diff --git a/migrations/sqlite/2018-05-25-232323_update_attachments_reference/down.sql b/migrations/sqlite/2018-05-25-232323_update_attachments_reference/down.sql
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/migrations/sqlite/2018-05-25-232323_update_attachments_reference/down.sql
diff --git a/migrations/sqlite/2018-05-25-232323_update_attachments_reference/up.sql b/migrations/sqlite/2018-05-25-232323_update_attachments_reference/up.sql
new file mode 100644
index 00000000..b7adb77e
--- /dev/null
+++ b/migrations/sqlite/2018-05-25-232323_update_attachments_reference/up.sql
@@ -0,0 +1,14 @@
+ALTER TABLE attachments RENAME TO oldAttachments;
+
+CREATE TABLE attachments (
+ id TEXT NOT NULL PRIMARY KEY,
+ cipher_uuid TEXT NOT NULL REFERENCES ciphers (uuid),
+ file_name TEXT NOT NULL,
+ file_size INTEGER NOT NULL
+
+);
+
+INSERT INTO attachments (id, cipher_uuid, file_name, file_size)
+SELECT id, cipher_uuid, file_name, file_size FROM oldAttachments;
+
+DROP TABLE oldAttachments; \ No newline at end of file
diff --git a/migrations/sqlite/2018-06-01-112529_update_devices_twofactor_remember/down.sql b/migrations/sqlite/2018-06-01-112529_update_devices_twofactor_remember/down.sql
new file mode 100644
index 00000000..291a97c5
--- /dev/null
+++ b/migrations/sqlite/2018-06-01-112529_update_devices_twofactor_remember/down.sql
@@ -0,0 +1 @@
+-- This file should undo anything in `up.sql` \ No newline at end of file
diff --git a/migrations/sqlite/2018-06-01-112529_update_devices_twofactor_remember/up.sql b/migrations/sqlite/2018-06-01-112529_update_devices_twofactor_remember/up.sql
new file mode 100644
index 00000000..aaad8eab
--- /dev/null
+++ b/migrations/sqlite/2018-06-01-112529_update_devices_twofactor_remember/up.sql
@@ -0,0 +1,3 @@
+ALTER TABLE devices
+ ADD COLUMN
+ twofactor_remember TEXT; \ No newline at end of file
diff --git a/migrations/sqlite/2018-07-11-181453_create_u2f_twofactor/down.sql b/migrations/sqlite/2018-07-11-181453_create_u2f_twofactor/down.sql
new file mode 100644
index 00000000..84b6ee63
--- /dev/null
+++ b/migrations/sqlite/2018-07-11-181453_create_u2f_twofactor/down.sql
@@ -0,0 +1,8 @@
+UPDATE users
+SET totp_secret = (
+ SELECT twofactor.data FROM twofactor
+ WHERE twofactor.type = 0
+ AND twofactor.user_uuid = users.uuid
+);
+
+DROP TABLE twofactor; \ No newline at end of file
diff --git a/migrations/sqlite/2018-07-11-181453_create_u2f_twofactor/up.sql b/migrations/sqlite/2018-07-11-181453_create_u2f_twofactor/up.sql
new file mode 100644
index 00000000..3e78e721
--- /dev/null
+++ b/migrations/sqlite/2018-07-11-181453_create_u2f_twofactor/up.sql
@@ -0,0 +1,15 @@
+CREATE TABLE twofactor (
+ uuid TEXT NOT NULL PRIMARY KEY,
+ user_uuid TEXT NOT NULL REFERENCES users (uuid),
+ type INTEGER NOT NULL,
+ enabled BOOLEAN NOT NULL,
+ data TEXT NOT NULL,
+
+ UNIQUE (user_uuid, type)
+);
+
+
+INSERT INTO twofactor (uuid, user_uuid, type, enabled, data)
+SELECT lower(hex(randomblob(16))) , uuid, 0, 1, u.totp_secret FROM users u where u.totp_secret IS NOT NULL;
+
+UPDATE users SET totp_secret = NULL; -- Instead of recreating the table, just leave the columns empty \ No newline at end of file
diff --git a/migrations/sqlite/2018-08-27-172114_update_ciphers/down.sql b/migrations/sqlite/2018-08-27-172114_update_ciphers/down.sql
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/migrations/sqlite/2018-08-27-172114_update_ciphers/down.sql
diff --git a/migrations/sqlite/2018-08-27-172114_update_ciphers/up.sql b/migrations/sqlite/2018-08-27-172114_update_ciphers/up.sql
new file mode 100644
index 00000000..624efd66
--- /dev/null
+++ b/migrations/sqlite/2018-08-27-172114_update_ciphers/up.sql
@@ -0,0 +1,3 @@
+ALTER TABLE ciphers
+ ADD COLUMN
+ password_history TEXT; \ No newline at end of file
diff --git a/migrations/sqlite/2018-09-10-111213_add_invites/down.sql b/migrations/sqlite/2018-09-10-111213_add_invites/down.sql
new file mode 100644
index 00000000..af3776cf
--- /dev/null
+++ b/migrations/sqlite/2018-09-10-111213_add_invites/down.sql
@@ -0,0 +1 @@
+DROP TABLE invitations; \ No newline at end of file
diff --git a/migrations/sqlite/2018-09-10-111213_add_invites/up.sql b/migrations/sqlite/2018-09-10-111213_add_invites/up.sql
new file mode 100644
index 00000000..b42e9a2a
--- /dev/null
+++ b/migrations/sqlite/2018-09-10-111213_add_invites/up.sql
@@ -0,0 +1,3 @@
+CREATE TABLE invitations (
+ email TEXT NOT NULL PRIMARY KEY
+); \ No newline at end of file
diff --git a/migrations/sqlite/2018-09-19-144557_add_kdf_columns/down.sql b/migrations/sqlite/2018-09-19-144557_add_kdf_columns/down.sql
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/migrations/sqlite/2018-09-19-144557_add_kdf_columns/down.sql
diff --git a/migrations/sqlite/2018-09-19-144557_add_kdf_columns/up.sql b/migrations/sqlite/2018-09-19-144557_add_kdf_columns/up.sql
new file mode 100644
index 00000000..bd98f40e
--- /dev/null
+++ b/migrations/sqlite/2018-09-19-144557_add_kdf_columns/up.sql
@@ -0,0 +1,7 @@
+ALTER TABLE users
+ ADD COLUMN
+ client_kdf_type INTEGER NOT NULL DEFAULT 0; -- PBKDF2
+
+ALTER TABLE users
+ ADD COLUMN
+ client_kdf_iter INTEGER NOT NULL DEFAULT 5000;
diff --git a/migrations/sqlite/2018-11-27-152651_add_att_key_columns/down.sql b/migrations/sqlite/2018-11-27-152651_add_att_key_columns/down.sql
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/migrations/sqlite/2018-11-27-152651_add_att_key_columns/down.sql
diff --git a/migrations/2018-11-27-152651_add_att_key_columns/up.sql b/migrations/sqlite/2018-11-27-152651_add_att_key_columns/up.sql
index 858d3778..4a73a8c9 100644
--- a/migrations/2018-11-27-152651_add_att_key_columns/up.sql
+++ b/migrations/sqlite/2018-11-27-152651_add_att_key_columns/up.sql
@@ -1,3 +1,3 @@
ALTER TABLE attachments
ADD COLUMN
- akey TEXT;
+ key TEXT; \ No newline at end of file
diff --git a/migrations/sqlite/2019-05-26-216651_rename_key_and_type_columns/down.sql b/migrations/sqlite/2019-05-26-216651_rename_key_and_type_columns/down.sql
new file mode 100644
index 00000000..4e6902aa
--- /dev/null
+++ b/migrations/sqlite/2019-05-26-216651_rename_key_and_type_columns/down.sql
@@ -0,0 +1,7 @@
+ALTER TABLE attachments RENAME COLUMN akey TO key;
+ALTER TABLE ciphers RENAME COLUMN atype TO type;
+ALTER TABLE devices RENAME COLUMN atype TO type;
+ALTER TABLE twofactor RENAME COLUMN atype TO type;
+ALTER TABLE users RENAME COLUMN akey TO key;
+ALTER TABLE users_organizations RENAME COLUMN akey TO key;
+ALTER TABLE users_organizations RENAME COLUMN atype TO type; \ No newline at end of file
diff --git a/migrations/sqlite/2019-05-26-216651_rename_key_and_type_columns/up.sql b/migrations/sqlite/2019-05-26-216651_rename_key_and_type_columns/up.sql
new file mode 100644
index 00000000..ab2c5b52
--- /dev/null
+++ b/migrations/sqlite/2019-05-26-216651_rename_key_and_type_columns/up.sql
@@ -0,0 +1,7 @@
+ALTER TABLE attachments RENAME COLUMN key TO akey;
+ALTER TABLE ciphers RENAME COLUMN type TO atype;
+ALTER TABLE devices RENAME COLUMN type TO atype;
+ALTER TABLE twofactor RENAME COLUMN type TO atype;
+ALTER TABLE users RENAME COLUMN key TO akey;
+ALTER TABLE users_organizations RENAME COLUMN key TO akey;
+ALTER TABLE users_organizations RENAME COLUMN type TO atype; \ No newline at end of file