fix case of fields table

This commit is contained in:
Damien Elmes 2021-09-07 10:22:22 +10:00
parent a13226c663
commit 6279015509
6 changed files with 15 additions and 10 deletions

View file

@ -1,5 +1,5 @@
SELECT DISTINCT name SELECT DISTINCT name
FROM FIELDS FROM fields
WHERE ntid IN ( WHERE ntid IN (
SELECT mid SELECT mid
FROM notes FROM notes

View file

@ -1,6 +1,6 @@
SELECT ord, SELECT ord,
name, name,
config config
FROM FIELDS FROM fields
WHERE ntid = ? WHERE ntid = ?
ORDER BY ord ORDER BY ord

View file

@ -1,2 +1,2 @@
INSERT INTO FIELDS (ntid, ord, name, config) INSERT INTO fields (ntid, ord, name, config)
VALUES (?, ?, ?, ?); VALUES (?, ?, ?, ?);

View file

@ -1,7 +1,7 @@
DROP TABLE config; DROP TABLE config;
DROP TABLE deck_config; DROP TABLE deck_config;
DROP TABLE tags; DROP TABLE tags;
DROP TABLE FIELDS; DROP TABLE fields;
DROP TABLE templates; DROP TABLE templates;
DROP TABLE notetypes; DROP TABLE notetypes;
DROP TABLE decks; DROP TABLE decks;

View file

@ -1,11 +1,11 @@
CREATE TABLE FIELDS ( CREATE TABLE fields (
ntid integer NOT NULL, ntid integer NOT NULL,
ord integer NOT NULL, ord integer NOT NULL,
name text NOT NULL COLLATE unicase, name text NOT NULL COLLATE unicase,
config blob NOT NULL, config blob NOT NULL,
PRIMARY KEY (ntid, ord) PRIMARY KEY (ntid, ord)
) without rowid; ) without rowid;
CREATE UNIQUE INDEX idx_fields_name_ntid ON FIELDS (name, ntid); CREATE UNIQUE INDEX idx_fields_name_ntid ON fields (name, ntid);
CREATE TABLE templates ( CREATE TABLE templates (
ntid integer NOT NULL, ntid integer NOT NULL,
ord integer NOT NULL, ord integer NOT NULL,

View file

@ -16,13 +16,18 @@ function fixFile(relpath: string, newText: string): void {
} }
function formatText(text: string): string { function formatText(text: string): string {
const newText: string = sqlFormatter.format(text, { let newText: string = sqlFormatter.format(text, {
indent: " ", indent: " ",
reservedWordCase: "upper", reservedWordCase: "upper",
}); });
// 'type' is treated as a reserved word, but Anki uses it in various sql // downcase some keywords that Anki uses in tables/columns
// tables, so we don't want it uppercased for (const keyword of ["type", "fields"]) {
return newText.replace(/\bTYPE\b/g, "type"); newText = newText.replace(
new RegExp(`\\b${keyword.toUpperCase()}\\b`, "g"),
keyword
);
}
return newText;
} }
let errorFound = false; let errorFound = false;