mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 06:05:24 +00:00
fix: keep text primary keys in the plugin data export
This commit is contained in:
1 parent
737e7cd7f7
commit
da3f0c7836
3 files changed
+27
-4
No files matched your search
@@ -52,6 +52,7 @@
|
||||
### Fixed
|
||||
|
||||
- Linking the desktop app to a server no longer stalls on the server dashboard after sign in
|
||||
- Exporting your data no longer fails when a plugin table has a text key, like saved passkeys
|
||||
|
||||
### Removed
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ export interface UserOwnedTable {
|
||||
otherUserColumns: string[];
|
||||
/** refHost columns. */
|
||||
hostColumns: string[];
|
||||
/** Columns that travel, as SQL names. The primary key and secrets do not. */
|
||||
/** Columns that travel, as SQL names. Auto ids and secrets do not. */
|
||||
columns: string[];
|
||||
/** The owner column is the primary key: one row per user. */
|
||||
userIsKey: boolean;
|
||||
@@ -57,9 +57,7 @@ export function listUserOwnedTables(): UserOwnedTable[] {
|
||||
.filter(
|
||||
([, column]) =>
|
||||
column === user[1] ||
|
||||
(column.type !== "id" &&
|
||||
!column.primaryKey &&
|
||||
column.type !== "encryptedText"),
|
||||
(column.type !== "id" && column.type !== "encryptedText"),
|
||||
)
|
||||
.map(([property, column]) => columnName(property, column)),
|
||||
userIsKey: !!user[1].primaryKey,
|
||||
|
||||
@@ -155,6 +155,30 @@ describe("plugin user data", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("exports a table with a text primary key", async () => {
|
||||
const credentials = defineTable("credential", {
|
||||
id: varchar(64).primaryKey(),
|
||||
userId: refUser().notNull(),
|
||||
label: text(),
|
||||
});
|
||||
for (const statement of createTableSql("sqlite", "fixture", credentials)) {
|
||||
sqlite.exec(statement);
|
||||
}
|
||||
registerTable("fixture", credentials);
|
||||
sqlite.exec(
|
||||
"INSERT INTO p_fixture_credential (id, user_id, label) VALUES ('abc', 'u1', 'key')",
|
||||
);
|
||||
|
||||
const file = new Database(":memory:");
|
||||
file.exec("CREATE TABLE users (id TEXT PRIMARY KEY)");
|
||||
file.exec("CREATE TABLE ssh_data (id INTEGER PRIMARY KEY)");
|
||||
file.exec("INSERT INTO users (id) VALUES ('u1')");
|
||||
await writeUserPluginTables(file, "u1");
|
||||
expect(file.prepare("SELECT * FROM p_fixture_credential").all()).toEqual([
|
||||
{ id: "abc", user_id: "u1", label: "key" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("writes large tables in chunks and lets the event loop run between them", async () => {
|
||||
const insert = sqlite.prepare(
|
||||
"INSERT INTO p_fixture_bookmark (user_id, path) VALUES ('u1', ?)",
|
||||
|
||||
Reference in new issue
Block a user