Breaking changes
As of 0.4.13
UDT fields must be in the same order as they are in the database. This is due to
scylla driver limitation that does not support named bind values. Earlier versions would
automatically order fields by name, but this is no longer the case as ORM could not work with
exiting UDTs.
Automatic migration Tool:
charybdis-migrate
tool that enables automatic migration to database without need to write
migrations by hand. It iterates over project files and generates migrations based on differences
between model definitions and database.
Installation
Usage
)
Automatic migration
-
charybdis-migrate
enables automatic migration to database without need to write migrations by hand. It expectssrc/models
files and generates migrations based on differences between model definitions and database. It supports following operations:-
Create new tables
-
Create new columns
-
Drop columns
-
Change field types (drop and recreate column
--drop-and-replace
flag) -
Create secondary indexes
-
Drop secondary indexes
-
Create UDTs
-
Create materialized views
-
Table options
⚠️ If table exists, table options will result in alter table query that without
CLUSTERING ORDER
andCOMPACT STORAGE
options.Model dropping is not added. If you removed model, you need to drop table manually.
-
-
Running migration
⚠️ If you are working with existing datasets, before running migration you need to make sure that your **model ** definitions structure matches the database in respect to table names, column names, column types, partition keys, clustering keys and secondary indexes so you don't alter structure accidentally. If structure is matched, it will not run any migrations. As mentioned above, in case there is no model definition for table, it will not drop it. In future, we will add
modelize
command that will generatesrc/models
files from existing data source. -
Global secondary indexes
If we have model:
resulting query will be:
CREATE INDEX ON users (username);
-
Local secondary Indexes
Indexes that are scoped to the partition key
resulting query will be:
CREATE INDEX ON menus((location), dish_type);
Define Tables
use charybdis_model;
use ;
Define UDT
use charybdis_udt_model;
use Text;
Define Materialized Views
use charybdis_view_model;
use ;
Resulting auto-generated migration query will be:
CREATE MATERIALIZED VIEW IF NOT EXISTS users_by_email
AS SELECT created_at, updated_at, username, email, id
FROM users
WHERE email IS NOT NULL AND id IS NOT NULL
PRIMARY KEY (email, id)