Skip to content

Commit c15e2b5

Browse files
authored
refactor!: uncouple fields from hard-coded values (#1354)
* refactor!: uncouple fields from hardcoded values * fix(tests): add missing db version fixtures * fix: correctly add datetime field as datetime in json migration * tests: update search library file * fix: implement review feedback and misc fixes * fix: implement additional feedback
1 parent de7face commit c15e2b5

26 files changed

Lines changed: 606 additions & 758 deletions

File tree

docs/library-changes.md

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ Migration from the legacy JSON format is provided via a walkthrough when opening
6464
| ------------------------------------------------------------------------------- | ------ | ----------------------------------------------- |
6565
| [v9.5.0-pr2](https://github.com/TagStudioDev/TagStudio/releases/tag/v9.5.0-pr2) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
6666

67-
- Repairs "Description" fields to use a TEXT_LINE key instead of a TEXT_BOX key.
68-
- Repairs tags that may have a disambiguation_id pointing towards a deleted tag.
67+
- ~~Repairs "Description" fields to use a TEXT_LINE key instead of a TEXT_BOX key.~~ _See [Version 200](#version-200)_
68+
- Repairs tags that may have a disambiguation_id pointing towards a deleted tag.
6969

7070
---
7171

@@ -75,9 +75,9 @@ Migration from the legacy JSON format is provided via a walkthrough when opening
7575
| ------------------------------------------------------------------------------- | ------ | ----------------------------------------------- |
7676
| [v9.5.0-pr4](https://github.com/TagStudioDev/TagStudio/releases/tag/v9.5.0-pr4) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
7777

78-
- Adds the `color_border` column to the `tag_colors` table. Used for instructing the [secondary color](colors.md#secondary-color) to apply to a tag's border as a new optional behavior.
79-
- Adds three new default colors: "Burgundy (TagStudio Shades)", "Dark Teal (TagStudio Shades)", and "Dark Lavender (TagStudio Shades)".
80-
- Updates Neon colors to use the new `color_border` property.
78+
- Adds the `color_border` column to the `tag_colors` table. Used for instructing the [secondary color](colors.md#secondary-color) to apply to a tag's border as a new optional behavior.
79+
- Adds three new default colors: "Burgundy (TagStudio Shades)", "Dark Teal (TagStudio Shades)", and "Dark Lavender (TagStudio Shades)".
80+
- Updates Neon colors to use the new `color_border` property.
8181

8282
---
8383

@@ -87,56 +87,75 @@ Migration from the legacy JSON format is provided via a walkthrough when opening
8787
| ----------------------------------------------------------------------- | ------ | ----------------------------------------------- |
8888
| [v9.5.2](https://github.com/TagStudioDev/TagStudio/releases/tag/v9.5.2) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
8989

90-
- Adds the `filename` column to the `entries` table. Used for sorting entries by filename in search results.
90+
- Adds the `filename` column to the `entries` table. Used for sorting entries by filename in search results.
9191

9292
---
9393

94-
### Version 100
94+
### Versions 100 - 1xx
95+
96+
#### Version 100
9597

9698
| Used From | Format | Location |
9799
| ---------------------------------------------------------------------------------------------------- | ------ | ----------------------------------------------- |
98100
| [74383e3](https://github.com/TagStudioDev/TagStudio/commit/74383e3c3c12f72be1481ab0b86c7360b95c2d85) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
99101

100-
- Introduces built-in minor versioning
101-
- The version number divided by 100 (and floored) constitutes the **major** version. Major version indicate breaking changes that prevent libraries from being opened in TagStudio versions older than the ones they were created in.
102-
- Values more precise than this ("ones" through "tens" columns) constitute the **minor** version. These indicate minor changes that don't prevent a newer library from being opened in an older version of TagStudio, as long as the major version is not also increased.
103-
- Swaps `parent_id` and `child_id` values in the `tag_parents` table
102+
- Introduces built-in minor versioning
103+
- The version number divided by 100 (and floored) constitutes the **major** version. Major version indicate breaking changes that prevent libraries from being opened in TagStudio versions older than the ones they were created in.
104+
- Values more precise than this ("ones" through "tens" columns) constitute the **minor** version. These indicate minor changes that don't prevent a newer library from being opened in an older version of TagStudio, as long as the major version is not also increased.
105+
- Swaps `parent_id` and `child_id` values in the `tag_parents` table
104106

105107
#### Version 101
106108

107-
| Used From | Format | Location |
108-
| ----------------------------------------------------------------------- | ------ | ----------------------------------------------- |
109-
| [v9.5.4](https://github.com/TagStudioDev/TagStudio/releases/tag/v9.5.4) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
109+
| Used From | Format | Location |
110+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ----------------------------------------------- |
111+
| [12e074b](https://github.com/TagStudioDev/TagStudio/commit/12e074b71d8860282b44e49e0e1a41b7a2e4bae8)/[v9.5.4](https://github.com/TagStudioDev/TagStudio/releases/tag/v9.5.4) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
110112

111-
- Deprecates the `preferences` table, set to be removed in a future TagStudio version.
112-
- Introduces the `versions` table
113-
- Has a string `key` column and an int `value` column
114-
- The `key` column stores one of two values: `'INITIAL'` and `'CURRENT'`
115-
- `'INITIAL'` stores the database version number in which in was created
116-
- Pre-existing databases set this number to `100`
117-
- `'CURRENT'` stores the current database version number
113+
- Deprecates the `preferences` table, set to be removed in a future TagStudio version.
114+
- Introduces the `versions` table
115+
- Has a string `key` column and an int `value` column
116+
- The `key` column stores one of two values: `'INITIAL'` and `'CURRENT'`
117+
- `'INITIAL'` stores the database version number in which in was created
118+
- Pre-existing databases set this number to `100`
119+
- `'CURRENT'` stores the current database version number
118120

119121
#### Version 102
120122

121-
| Used From | Format | Location |
122-
| ----------------------------------------------------------------------- | ------ | ----------------------------------------------- |
123-
| [v9.5.4](https://github.com/TagStudioDev/TagStudio/releases/tag/v9.5.4) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
124-
125-
- Applies repairs to the `tag_parents` table created in [version 100](#version-100), removing rows that reference tags that have been deleted.
123+
| Used From | Format | Location |
124+
| ---------------------------------------------------------------------------------------------------- | ------ | ----------------------------------------------- |
125+
| [71d0425](https://github.com/TagStudioDev/TagStudio/commit/71d04254cf87f4200bb7ffc81656e50dfb122e4d) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
126126

127-
#### Version 103
127+
- Applies repairs to the `tag_parents` table created in [version 100](#version-100), removing rows that reference tags that have been deleted.
128128

129-
| Used From | Format | Location |
130-
| ----------------------------------------------------------------------- | ------ | ----------------------------------------------- |
131-
| [#1139](https://github.com/TagStudioDev/TagStudio/pull/1139) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
129+
| Used From | Format | Location |
130+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ----------------------------------------------- |
131+
| [88d0b47](https://github.com/TagStudioDev/TagStudio/commit/88d0b47a86821ccfadba653f30a515abce5b24b0)/[v9.5.7](https://github.com/TagStudioDev/TagStudio/releases/tag/v9.5.7) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
132132

133-
- Adds the `is_hidden` column to the `tags` table (default `0`). Used for excluding entries tagged with hidden tags from library searches.
134-
- Sets the `is_hidden` field on the built-in Archived tag to `1`, to match the Archived tag now being hidden by default.
133+
- Adds the `is_hidden` column to the `tags` table (default `0`). Used for excluding entries tagged with hidden tags from library searches.
134+
- Sets the `is_hidden` field on the built-in Archived tag to `1`, to match the Archived tag now being hidden by default.
135135

136136
#### Version 104
137137

138-
| Used From | Format | Location |
139-
| ----------------------------------------------------------------------- | ------ | ----------------------------------------------- |
140-
| [#1298](https://github.com/TagStudioDev/TagStudio/pull/1298) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
138+
| Used From | Format | Location |
139+
| ---------------------------------------------------------------------------------------------------- | ------ | ----------------------------------------------- |
140+
| [ad2cbbc](https://github.com/TagStudioDev/TagStudio/commit/ad2cbbca483018d245b44348e2c4f5a0e0bb28f1) | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
141141

142142
- Removes the `preferences` table, after migrating the contained extension list to the .ts_ignore file, if necessary.
143+
144+
### Versions 200 - 2xx
145+
146+
#### Version 200
147+
148+
| Used From | Format | Location |
149+
| --------- | ------ | ----------------------------------------------- |
150+
| TBD | SQLite | `<Library Folder>`/.TagStudio/ts_library.sqlite |
151+
152+
- Adds `text_field_templates` and `date_field_templates` tables.
153+
- Drops `boolean_fields` and `value_type` tables.
154+
- Adds `name` columns to `text_fields` and `datetime_fields` tables.
155+
- Values in the `name` columns are taken from the `type_key` columns and are changed to "Title Case".
156+
- **Example:** "DATE_CREATED" -> "Date Created"
157+
- Drops `position` columns from `text_fields` and `datetime_fields` tables.
158+
- Adds `is_multiline` column to `text_fields` table.
159+
- Values are set to `TRUE` if the field row was previously a "TEXT_BOX" type.
160+
- Repairs existing "Description" fields inside the `text_fields` table to have their `is_multiline` column set to `TRUE` _(Previously done in [Version 7](#version-7))_.
161+
- Repairs existing "Comments" fields inside the `text_fields` table to have their `is_multiline` column set to `TRUE`.

src/tagstudio/core/library/alchemy/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
DB_VERSION_CURRENT_KEY: str = "CURRENT"
1212
DB_VERSION_INITIAL_KEY: str = "INITIAL"
13-
DB_VERSION: int = 104
13+
DB_VERSION: int = 200
1414

1515
TAG_CHILDREN_QUERY = text("""
1616
WITH RECURSIVE ChildTags AS (

src/tagstudio/core/library/alchemy/db.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,3 @@ def make_tables(engine: Engine) -> None:
6666
except OperationalError as e:
6767
logger.error("Could not initialize built-in tags", error=e)
6868
conn.rollback()
69-
70-
71-
def drop_tables(engine: Engine) -> None:
72-
logger.info("dropping db tables")
73-
Base.metadata.drop_all(engine)

src/tagstudio/core/library/alchemy/enums.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,3 @@ def with_search_query(self, search_query: str) -> "BrowsingState":
152152

153153
def with_show_hidden_entries(self, show_hidden_entries: bool) -> "BrowsingState":
154154
return replace(self, show_hidden_entries=show_hidden_entries)
155-
156-
157-
class FieldTypeEnum(enum.Enum):
158-
TEXT_LINE = "Text Line"
159-
TEXT_BOX = "Text Box"
160-
TAGS = "Tags"
161-
DATETIME = "Datetime"
162-
BOOLEAN = "Checkbox"

0 commit comments

Comments
 (0)