Refactored workspaces API and corrected method headers + fixed bug caused by migration failures

co-authored-by: kay@zed.dev
This commit is contained in:
Mikayla Maki 2022-10-27 16:02:14 -07:00
parent 3451a3c7fe
commit ddecba143f
5 changed files with 12 additions and 38 deletions

View file

@ -4,14 +4,10 @@ use rusqlite::OptionalExtension;
use super::Db;
pub(crate) const KVP_M_1: &str = "
BEGIN TRANSACTION;
CREATE TABLE kv_store(
key TEXT PRIMARY KEY,
value TEXT NOT NULL
) STRICT;
COMMIT;
";
impl Db {

View file

@ -75,8 +75,6 @@ pub struct SerializedPane {
}
pub(crate) const PANE_M_1: &str = "
BEGIN TRANSACTION;
CREATE TABLE dock_panes(
dock_pane_id INTEGER PRIMARY KEY,
workspace_id INTEGER NOT NULL,
@ -131,8 +129,6 @@ CREATE TABLE dock_items(
FOREIGN KEY(dock_pane_id) REFERENCES dock_panes(dock_pane_id) ON DELETE CASCADE,
FOREIGN KEY(item_id) REFERENCES items(item_id)ON DELETE CASCADE
) STRICT;
COMMIT;
";
#[derive(Default, Debug)]
@ -222,9 +218,7 @@ mod tests {
fn test_basic_dock_pane() {
let db = Db::open_in_memory();
let workspace = db.make_new_workspace::<String>(&[]);
db.update_worktrees(&workspace.workspace_id, &["/tmp"]);
let workspace = db.workspace_for_roots(&["/tmp"]);
db.save_dock_pane(SerializedDockPane {
workspace: workspace.workspace_id,

View file

@ -17,8 +17,6 @@ use super::Db;
// you might want to update some of the parsing code as well, I've left the variations in but commented
// out
pub(crate) const WORKSPACE_M_1: &str = "
BEGIN TRANSACTION;
CREATE TABLE workspaces(
workspace_id INTEGER PRIMARY KEY,
timestamp TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL
@ -30,8 +28,6 @@ CREATE TABLE worktree_roots(
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id) ON DELETE CASCADE
PRIMARY KEY(worktree_root, workspace_id)
) STRICT;
COMMIT;
";
#[derive(Debug, PartialEq, Eq, Copy, Clone, Default)]
@ -68,7 +64,7 @@ impl Db {
}
}
pub fn make_new_workspace<P>(&self, worktree_roots: &[P]) -> SerializedWorkspace
fn make_new_workspace<P>(&self, worktree_roots: &[P]) -> SerializedWorkspace
where
P: AsRef<Path> + Debug,
{
@ -158,7 +154,7 @@ impl Db {
});
}
pub fn last_workspace_id(&self) -> Option<WorkspaceId> {
fn last_workspace_id(&self) -> Option<WorkspaceId> {
fn logic(connection: &mut Connection) -> Result<Option<WorkspaceId>> {
let mut stmt = connection
.prepare("SELECT workspace_id FROM workspaces ORDER BY timestamp DESC LIMIT 1")?;
@ -432,7 +428,7 @@ mod tests {
use super::WorkspaceId;
#[test]
fn test_worktree_for_roots() {
fn test_new_worktrees_for_roots() {
let db = Db::open_in_memory();
// Test creation in 0 case