mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-09 21:32:38 +00:00
fix(host-metrics): exclude image and firmware filesystems (#1469)
* fix(host-metrics): exclude image and firmware filesystems * fix(ci): build plugin SDK before dependent checks * fix(mysql): keep plugin settings scope indexes within limits * test(mysql): refresh reviewed plugin upgrade SQL
This commit is contained in:
1 parent
c38c2e84b8
commit
710f545e34
14 files changed
+4938
-16
No files matched your search
@@ -142,7 +142,7 @@ function camelToSnake(value) {
|
||||
return value.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
|
||||
}
|
||||
|
||||
function keyTables(source, tables, keyed) {
|
||||
function keyTables(source, tables, keyed, dialect) {
|
||||
let out = "";
|
||||
let cursor = 0;
|
||||
for (const { table, index, end } of tables) {
|
||||
@@ -150,10 +150,17 @@ function keyTables(source, tables, keyed) {
|
||||
const columns = keyed.get(table);
|
||||
out += source
|
||||
.slice(index, end)
|
||||
.replace(/\btext\("([a-z0-9_]+)"\)/g, (whole, col) =>
|
||||
columns.has(col)
|
||||
? `varchar("${col}", { length: ${KEY_LENGTH} })`
|
||||
: whole,
|
||||
.replace(
|
||||
/\btext\("([a-z0-9_]+)"(?:,\s*\{\s*enum:\s*(\[[^\]]*\]),?\s*\})?\)/g,
|
||||
(whole, col, values) => {
|
||||
// Closed sets stay compact without shortening identifiers or keys.
|
||||
if (values && dialect === "mysql")
|
||||
return `mysqlEnum("${col}", ${values})`;
|
||||
const options = values ? `, enum: ${values}` : "";
|
||||
return columns.has(col)
|
||||
? `varchar("${col}", { length: ${KEY_LENGTH}${options} })`
|
||||
: whole;
|
||||
},
|
||||
);
|
||||
cursor = end;
|
||||
}
|
||||
@@ -165,7 +172,7 @@ function transform(source, dialect) {
|
||||
const isPg = dialect === "postgres";
|
||||
// Key-bearing strings must be indexable. First, while the table offsets
|
||||
// still match the source.
|
||||
let out = keyTables(source, tables, keyed);
|
||||
let out = keyTables(source, tables, keyed, dialect);
|
||||
|
||||
// Autoincrement primary keys, before the plain integer rule below.
|
||||
out = out.replace(
|
||||
@@ -235,6 +242,7 @@ function transform(source, dialect) {
|
||||
]
|
||||
: [
|
||||
"mysqlTable",
|
||||
"mysqlEnum",
|
||||
"text",
|
||||
"varchar",
|
||||
"int",
|
||||
|
||||
@@ -141,6 +141,27 @@ describe("mysql output", () => {
|
||||
expect(out).toContain('varchar("user_id", { length: 255 })');
|
||||
expect(out).toContain('text("name")');
|
||||
});
|
||||
|
||||
it("keeps closed scopes compact in four-column setting indexes", () => {
|
||||
const source = `import { sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
|
||||
export const pluginSettings = sqliteTable("plugin_settings", {
|
||||
pluginId: text("plugin_id").notNull(),
|
||||
scope: text("scope", { enum: ["admin", "user", "host", "secret"] }).notNull(),
|
||||
scopeId: text("scope_id"),
|
||||
key: text("key").notNull(),
|
||||
}, (table) => [uniqueIndex("scope_key").on(table.pluginId, table.scope, table.scopeId, table.key)]);
|
||||
`;
|
||||
const mysql = transform(source, "mysql");
|
||||
expect(mysql).toContain(
|
||||
'mysqlEnum("scope", ["admin", "user", "host", "secret"])',
|
||||
);
|
||||
for (const name of ["plugin_id", "scope_id", "key"]) {
|
||||
expect(mysql).toContain(`varchar("${name}", { length: 255 })`);
|
||||
}
|
||||
expect(transform(source, "postgres")).toContain(
|
||||
'varchar("scope", { length: 255, enum: ["admin", "user", "host", "secret"] })',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("determinism", () => {
|
||||
|
||||
Reference in new issue
Block a user