fix case of fields table

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,11 @@
CREATE TABLE FIELDS (
CREATE TABLE fields (
ntid integer NOT NULL,
ord integer NOT NULL,
name text NOT NULL COLLATE unicase,
config blob NOT NULL,
PRIMARY KEY (ntid, ord)
) 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 (
ntid 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 {
const newText: string = sqlFormatter.format(text, {
let newText: string = sqlFormatter.format(text, {
indent: " ",
reservedWordCase: "upper",
});
// 'type' is treated as a reserved word, but Anki uses it in various sql
// tables, so we don't want it uppercased
return newText.replace(/\bTYPE\b/g, "type");
// downcase some keywords that Anki uses in tables/columns
for (const keyword of ["type", "fields"]) {
newText = newText.replace(
new RegExp(`\\b${keyword.toUpperCase()}\\b`, "g"),
keyword
);
}
return newText;
}
let errorFound = false;