Add cdb schema V2#3044
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a “schema V2” evolution for the card database and updates the client DB loader to consume the new columns while attempting to remain compatible with older databases.
Changes:
- Extends the
datastable withscaleand additionalsetcodestorage (setcode2..4) and migrates existing packed scale / special setcode data. - Updates
DataManager::ReadDBto read either the legacySELECTshape or the new V2SELECTshape. - Removes the legacy “extra_setcode” patch-up path for V2 databases (kept only for legacy DBs).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| resource/migrate.sql | Adds schema migration steps for scale and setcode2..4 and commits within a transaction. |
| gframe/data_manager.cpp | Adds V2 SELECT + parsing and runtime selection between legacy/V2 DB layouts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Migration PlanDatabase with schema V1The current databases still work after this PR. Migrate to schema v2The sqlite commands for adding new columns are in sqlite3 cards.cdb < migrate.sql |
|
I think we should make a todo list for current ecosystem, like:
|
|
what about link arrows in defense column, and more categories |
I would say there are too much. Not this little, including some MyCard internal systems |
|
and I suggest to have a 3rd table to store the schema version. |
https://github.com/purerosefallen/ygopro-cdb-encode in fact this one, and other js/ts projects reading cdb should migrate to this project |
Please stop shifting your responsibility to others. |
Link markers Scale should be put in another column because it is not mutual exclusive with level. Category |
I think a version control marker in cdb format is necessary, just as how In case we have v3, we may route to correct SQL to parse In addition, I suggest we make a driver layer, something like |
|
https://sqlite.org/pragma.html#pragma_user_version The user_version pragma will get or set the value of the user-version integer at offset 60 in the database header. The user-version is an integer that is available to applications to use however they want. SQLite makes no use of the user-version itself. How about storing pragma version in |
|
nope we need a specific table. |
|
and again, unless necessary, we should keep using general SQL thing rather than SQLite-exclusive stmt |
|
and some ORMs like TypeORM, SQLModel does not support schema version in header. it's would make things built with those libs hard to maintain. I don't agree on using SQLite user_version |
|
@mercury233 @purerosefallen @Wind2009-Louse
|
a new table |
|
Converting this to draft because it's considered half-done for lack of version table while a version table plan was introduced |
|
I prefer feature detection over versioning in database. |
Co-authored-by: Copilot <copilot@github.com>
Could you explain more? I think versioning could be a way. |
|
I think this PR can be merged. During that time, we may plan to migrate those internal systems, but it could take months to do so. |
the new cdb schema is being discussed in #3044 and this *middle* format is nowhere used. This file may be reintroduced in that PR.
| /sqlite3/*.c | ||
| /sqlite3/*.h |
There was a problem hiding this comment.
| /sqlite3/*.c | |
| /sqlite3/*.h | |
| /sqlite3 | |
| !/sqlite3/migrate.sql |
btw I don't think it is a good idea to put that sql file here
There was a problem hiding this comment.
Where should I put this file ?
|
I suggest this is an opportunity to resolve the hardcoding of cards with double names like CARD_MARINE_DOLPHIN. |
any specific plans? |
|
some possible choice:
CREATE TABLE datas (
id INTEGER PRIMARY KEY,
rule_code TEXT
);
maybe this is suitable for setcodes |
I would go with 2 |
|
ygopro is known for abusing bitwise logic. |
Problem
There are many problems in the current schema.
rule_code
See Fluorohydride/ygopro-core#823
scale
Now the scale is packed into
levelcolumn.Packing multiple unrelated properties into the same column is considered a poor practice in database design.
Violates database normalization
Normalization is a design principle that separates data into logical tables and columns to reduce redundancy and improve clarity.
Packing multiple attributes into one column breaks this rule, and it makes the schema less readable, harder to understand, and more error-prone.
Harder to query
Queries are harder to write and maintain.
You must remember which bit means what.
Even simple queries become more complex, requiring constant use of bitwise operations.
Poor indexing support
SQLite indexes individual columns, but not individual bits inside an integer.
If you pack 4 values into one INTEGER column, it cannot index each flag efficiently.
Queries on individual bits won’t benefit from indexes, resulting in full table scans.
It can hurt performance, especially when the table grows.
Difficult to maintain
With individual columns, adding or changing values is straightforward.
But when values are packed into a single field, even basic read or write operations require bitwise manipulation.
For example:
What is the level of a card with a
levelcolumn of 50528266?If the level needs to be changed to 11, what is the new value of
level?Minimal space savings in SQLite
SQLite is already very efficient at storing integers.
It uses variable-length integers internally, which take only as many bytes as needed.
The space saving from packing bits is negligible.
setcode
There are some cards with more than 4 setcode entries:
8512558 Utopic Onomatopoeia
55088578 Onomatokage
They are handled by table lookup now, but it is not a good approach.
Solution
Require:
Fluorohydride/ygopro-core#802
Add the following columns to the database:
datas.rule_code,
datas.scale,
datas.setcode2,
datas.setcode3,
datas.setcode4,
Action Required for Third-Party Tool Maintainers
I suggest that third-party applications that rely on implicit SQL syntax update their queries.
Not recommended (will crash):
Correct (future-proof):
@mercury233 @purerosefallen @Wind2009-Louse @fallenstardust