Code Monkey home page Code Monkey logo

Comments (5)

mprasil avatar mprasil commented on May 13, 2024

Shouldn't be too hard to implement, but there needs to be some migration SQL unless we're Ok with breaking the schema. Any thoughts on that?

from vaultwarden.

dani-garcia avatar dani-garcia commented on May 13, 2024

Yeah, you are right about that. We also need to change the Ciphers table because currently user_uuid can't be null, and that doesn't make sense when the cipher is owned by an organization.

I personally don't mind breaking the schema if necessary, but in this case I think a migration would be reasonably easy. I'm thinking something like this:

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 users_ciphers (
  user_uuid   TEXT NOT NULL REFERENCES users (uuid),
  cipher_uuid TEXT NOT NULL REFERENCES ciphers (uuid),
  folder_uuid TEXT NOT NULL REFERENCES folders (uuid),

  PRIMARY KEY (user_uuid, cipher_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 users_ciphers (user_uuid, cipher_uuid, folder_uuid)
SELECT user_uuid, uuid, folder_uuid FROM oldCiphers WHERE folder_uuid IS NOT NULL;


DROP TABLE oldCiphers;

Something like that would be on the up.sql file, and the reverse process would be on the down.sql.

from vaultwarden.

mprasil avatar mprasil commented on May 13, 2024

I don't think we can really provide down.sql as you can map folders one way, but not the other way around (for example when two users have the cipher in their folders)

Is diesel fine with one way updates?

from vaultwarden.

dani-garcia avatar dani-garcia commented on May 13, 2024

Yeah, I didn't think of that.

I imagine diesel shoudn't have a problem as long as we don't choose to revert a migration, and I don't think we have a use for that.
In any case, if there is a problem, we could put folder_uuid to null in the down.sql and that would simply delete the folder assotiations, but we would still have the ciphers, which I guess is better than nothing.

from vaultwarden.

dani-garcia avatar dani-garcia commented on May 13, 2024

This should be fixed now with your PR, so I'm closing it.

from vaultwarden.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.