Skip to content

Commit be1bd22

Browse files
Disable column type changes in an automigration (#3178)
# Description of Changes <!-- Please describe your change, mention any related tickets, and so on here. --> Disables automigrations for column type changes # API and ABI breaking changes <!-- If this is an API or ABI breaking change, please apply the corresponding GitHub label. --> None # Expected complexity level and risk <!-- How complicated do you think these changes are? Grade on a scale from 1 to 5, where 1 is a trivial change, and 5 is a deep-reaching and complex change. This complexity rating applies not only to the complexity apparent in the diff, but also to its interactions with existing and future code. If you answered more than a 2, explain what is complex about the PR, and what other components it interacts with in potentially concerning ways. --> 0 # Testing <!-- Describe any testing you've done, and any testing you'd like your reviewers to do, so that you're confident that all the changes work as expected! --> - [x] Updated smoketests
1 parent a862ba9 commit be1bd22

File tree

3 files changed

+20
-65
lines changed

3 files changed

+20
-65
lines changed

crates/core/src/db/relational_db.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ impl RelationalDB {
10431043
Ok(self.inner.alter_table_access_mut_tx(tx, name, access)?)
10441044
}
10451045

1046+
#[allow(unused)]
10461047
pub(crate) fn alter_table_row_type(
10471048
&self,
10481049
tx: &mut MutTx,

crates/core/src/db/update.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use spacetimedb_lib::AlgebraicValue;
99
use spacetimedb_primitives::{ColSet, TableId};
1010
use spacetimedb_schema::auto_migrate::{AutoMigratePlan, ManualMigratePlan, MigratePlan};
1111
use spacetimedb_schema::def::TableDef;
12-
use spacetimedb_schema::schema::{column_schemas_from_defs, IndexSchema, Schema, SequenceSchema, TableSchema};
12+
use spacetimedb_schema::schema::{IndexSchema, Schema, SequenceSchema, TableSchema};
1313
use std::sync::Arc;
1414

1515
/// The logger used for by [`update_database`] and friends.
@@ -222,14 +222,8 @@ fn auto_migrate_database(
222222
);
223223
stdb.drop_sequence(tx, sequence_schema.sequence_id)?;
224224
}
225-
spacetimedb_schema::auto_migrate::AutoMigrateStep::ChangeColumns(table_name) => {
226-
let table_def = plan.new.stored_in_table_def(table_name).unwrap();
227-
let table_id = stdb.table_id_from_name_mut(tx, table_name).unwrap().unwrap();
228-
let column_schemas = column_schemas_from_defs(plan.new, &table_def.columns, table_id);
229-
230-
log!(logger, "Changing columns of table `{}`", table_name);
231-
232-
stdb.alter_table_row_type(tx, table_id, column_schemas)?;
225+
spacetimedb_schema::auto_migrate::AutoMigrateStep::ChangeColumns(_table_name) => {
226+
anyhow::bail!("Unsupported: Changing column types");
233227
}
234228
spacetimedb_schema::auto_migrate::AutoMigrateStep::ChangeAccess(table_name) => {
235229
let table_def = plan.new.stored_in_table_def(table_name).unwrap();

smoketests/tests/auto_migration.py

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,23 @@
44

55

66
class AddTableAutoMigration(Smoketest):
7-
MODULE_CODE_INIT = """
7+
MODULE_CODE = """
88
use spacetimedb::{log, ReducerContext, Table, SpacetimeType};
9-
use PersonKind::*;
109
1110
#[spacetimedb::table(name = person, public)]
1211
pub struct Person {
1312
name: String,
14-
kind: PersonKind,
1513
}
1614
1715
#[spacetimedb::reducer]
18-
pub fn add_person(ctx: &ReducerContext, name: String, kind: String) {
19-
let kind = kind_from_string(kind);
20-
ctx.db.person().insert(Person { name, kind });
16+
pub fn add_person(ctx: &ReducerContext, name: String) {
17+
ctx.db.person().insert(Person { name });
2118
}
2219
2320
#[spacetimedb::reducer]
2421
pub fn print_persons(ctx: &ReducerContext, prefix: String) {
2522
for person in ctx.db.person().iter() {
26-
let kind = kind_to_string(person.kind);
27-
log::info!("{prefix}: {} - {kind}", person.name);
23+
log::info!("{}: {}", prefix, person.name);
2824
}
2925
}
3026
@@ -43,47 +39,11 @@ class AddTableAutoMigration(Smoketest):
4339
4440
#[spacetimedb::client_visibility_filter]
4541
const PERSON_VISIBLE: spacetimedb::Filter = spacetimedb::Filter::Sql("SELECT * FROM person");
46-
"""
47-
48-
MODULE_CODE = MODULE_CODE_INIT + """
49-
#[derive(SpacetimeType, Clone, Copy, PartialEq, Eq)]
50-
pub enum PersonKind {
51-
Student,
52-
}
53-
54-
fn kind_from_string(_: String) -> PersonKind {
55-
Student
56-
}
57-
58-
fn kind_to_string(Student: PersonKind) -> &'static str {
59-
"Student"
60-
}
6142
"""
6243

6344
MODULE_CODE_UPDATED = (
64-
MODULE_CODE_INIT
45+
MODULE_CODE
6546
+ """
66-
#[derive(SpacetimeType, Clone, Copy, PartialEq, Eq)]
67-
pub enum PersonKind {
68-
Student,
69-
Professor,
70-
}
71-
72-
fn kind_from_string(kind: String) -> PersonKind {
73-
match &*kind {
74-
"Student" => Student,
75-
"Professor" => Professor,
76-
_ => panic!(),
77-
}
78-
}
79-
80-
fn kind_to_string(kind: PersonKind) -> &'static str {
81-
match kind {
82-
Student => "Student",
83-
Professor => "Professor",
84-
}
85-
}
86-
8747
#[spacetimedb::table(name = book, public)]
8848
pub struct Book {
8949
isbn: String,
@@ -129,14 +89,14 @@ def test_add_table_auto_migration(self):
12989
logging.info("Initial publish complete")
13090
# initial module code is already published by test framework
13191

132-
self.call("add_person", "Robert", "Student")
133-
self.call("add_person", "Julie", "Student")
134-
self.call("add_person", "Samantha", "Student")
92+
self.call("add_person", "Robert")
93+
self.call("add_person", "Julie")
94+
self.call("add_person", "Samantha")
13595
self.call("print_persons", "BEFORE")
13696
logs = self.logs(100)
137-
self.assertIn("BEFORE: Samantha - Student", logs)
138-
self.assertIn("BEFORE: Julie - Student", logs)
139-
self.assertIn("BEFORE: Robert - Student", logs)
97+
self.assertIn("BEFORE: Samantha", logs)
98+
self.assertIn("BEFORE: Julie", logs)
99+
self.assertIn("BEFORE: Robert", logs)
140100

141101
logging.info(
142102
"Initial operations complete, updating module without clear",
@@ -160,16 +120,16 @@ def test_add_table_auto_migration(self):
160120

161121
self.logs(100)
162122

163-
self.call("add_person", "Husserl", "Professor")
123+
self.call("add_person", "Husserl")
164124
self.call("add_book", "1234567890")
165125
self.call("print_persons", "AFTER_PERSON")
166126
self.call("print_books", "AFTER_BOOK")
167127

168128
logs = self.logs(100)
169-
self.assertIn("AFTER_PERSON: Samantha - Student", logs)
170-
self.assertIn("AFTER_PERSON: Julie - Student", logs)
171-
self.assertIn("AFTER_PERSON: Robert - Student", logs)
172-
self.assertIn("AFTER_PERSON: Husserl - Professor", logs)
129+
self.assertIn("AFTER_PERSON: Samantha", logs)
130+
self.assertIn("AFTER_PERSON: Julie", logs)
131+
self.assertIn("AFTER_PERSON: Robert", logs)
132+
self.assertIn("AFTER_PERSON: Husserl", logs)
173133
self.assertIn("AFTER_BOOK: 1234567890", logs)
174134

175135

0 commit comments

Comments
 (0)