Transform paths column to null-separated
This commit is contained in:
parent
5abe0134ad
commit
5474a310f7
2 changed files with 21 additions and 6 deletions
|
@ -58,11 +58,7 @@ impl PathList {
|
||||||
let mut paths: Vec<PathBuf> = if serialized.paths.is_empty() {
|
let mut paths: Vec<PathBuf> = if serialized.paths.is_empty() {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
} else {
|
} else {
|
||||||
serde_json::from_str::<Vec<PathBuf>>(&serialized.paths)
|
serialized.paths.split('\0').map(PathBuf::from).collect()
|
||||||
.unwrap_or(Vec::new())
|
|
||||||
.into_iter()
|
|
||||||
.map(|s| SanitizedPath::from(s).into())
|
|
||||||
.collect()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut order: Vec<usize> = serialized
|
let mut order: Vec<usize> = serialized
|
||||||
|
@ -85,7 +81,13 @@ impl PathList {
|
||||||
pub fn serialize(&self) -> SerializedPathList {
|
pub fn serialize(&self) -> SerializedPathList {
|
||||||
use std::fmt::Write as _;
|
use std::fmt::Write as _;
|
||||||
|
|
||||||
let paths = serde_json::to_string(&self.paths).unwrap_or_default();
|
let mut paths = String::new();
|
||||||
|
for path in self.paths.iter() {
|
||||||
|
if !paths.is_empty() {
|
||||||
|
paths.push('\0');
|
||||||
|
}
|
||||||
|
paths.push_str(&path.to_string_lossy());
|
||||||
|
}
|
||||||
|
|
||||||
let mut order = String::new();
|
let mut order = String::new();
|
||||||
for ix in self.order.iter() {
|
for ix in self.order.iter() {
|
||||||
|
|
|
@ -605,6 +605,19 @@ impl Domain for WorkspaceDb {
|
||||||
|
|
||||||
CREATE UNIQUE INDEX ix_workspaces_location ON workspaces(ssh_connection_id, paths);
|
CREATE UNIQUE INDEX ix_workspaces_location ON workspaces(ssh_connection_id, paths);
|
||||||
),
|
),
|
||||||
|
sql!(
|
||||||
|
UPDATE workspaces
|
||||||
|
SET paths = CASE
|
||||||
|
WHEN substr(paths, 1, 2) = '[' || '"' AND substr(paths, -2, 2) = ']' || '"' THEN
|
||||||
|
replace(
|
||||||
|
substr(paths, 2, length(paths) - 2),
|
||||||
|
'"' || ',' || '"',
|
||||||
|
'\0'
|
||||||
|
)
|
||||||
|
ELSE
|
||||||
|
replace(paths, ',', '\0')
|
||||||
|
END
|
||||||
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Allow recovering from bad migration
|
// Allow recovering from bad migration
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue