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
This commit is contained in:
joshua-spacetime
2025-08-21 10:18:24 -07:00
committed by GitHub
parent a862ba9373
commit be1bd22518
3 changed files with 20 additions and 65 deletions
+1
View File
@@ -1043,6 +1043,7 @@ impl RelationalDB {
Ok(self.inner.alter_table_access_mut_tx(tx, name, access)?)
}
#[allow(unused)]
pub(crate) fn alter_table_row_type(
&self,
tx: &mut MutTx,
+3 -9
View File
@@ -9,7 +9,7 @@ use spacetimedb_lib::AlgebraicValue;
use spacetimedb_primitives::{ColSet, TableId};
use spacetimedb_schema::auto_migrate::{AutoMigratePlan, ManualMigratePlan, MigratePlan};
use spacetimedb_schema::def::TableDef;
use spacetimedb_schema::schema::{column_schemas_from_defs, IndexSchema, Schema, SequenceSchema, TableSchema};
use spacetimedb_schema::schema::{IndexSchema, Schema, SequenceSchema, TableSchema};
use std::sync::Arc;
/// The logger used for by [`update_database`] and friends.
@@ -222,14 +222,8 @@ fn auto_migrate_database(
);
stdb.drop_sequence(tx, sequence_schema.sequence_id)?;
}
spacetimedb_schema::auto_migrate::AutoMigrateStep::ChangeColumns(table_name) => {
let table_def = plan.new.stored_in_table_def(table_name).unwrap();
let table_id = stdb.table_id_from_name_mut(tx, table_name).unwrap().unwrap();
let column_schemas = column_schemas_from_defs(plan.new, &table_def.columns, table_id);
log!(logger, "Changing columns of table `{}`", table_name);
stdb.alter_table_row_type(tx, table_id, column_schemas)?;
spacetimedb_schema::auto_migrate::AutoMigrateStep::ChangeColumns(_table_name) => {
anyhow::bail!("Unsupported: Changing column types");
}
spacetimedb_schema::auto_migrate::AutoMigrateStep::ChangeAccess(table_name) => {
let table_def = plan.new.stored_in_table_def(table_name).unwrap();
+16 -56
View File
@@ -4,27 +4,23 @@ import logging
class AddTableAutoMigration(Smoketest):
MODULE_CODE_INIT = """
MODULE_CODE = """
use spacetimedb::{log, ReducerContext, Table, SpacetimeType};
use PersonKind::*;
#[spacetimedb::table(name = person, public)]
pub struct Person {
name: String,
kind: PersonKind,
}
#[spacetimedb::reducer]
pub fn add_person(ctx: &ReducerContext, name: String, kind: String) {
let kind = kind_from_string(kind);
ctx.db.person().insert(Person { name, kind });
pub fn add_person(ctx: &ReducerContext, name: String) {
ctx.db.person().insert(Person { name });
}
#[spacetimedb::reducer]
pub fn print_persons(ctx: &ReducerContext, prefix: String) {
for person in ctx.db.person().iter() {
let kind = kind_to_string(person.kind);
log::info!("{prefix}: {} - {kind}", person.name);
log::info!("{}: {}", prefix, person.name);
}
}
@@ -43,47 +39,11 @@ pub struct Vector2 {
#[spacetimedb::client_visibility_filter]
const PERSON_VISIBLE: spacetimedb::Filter = spacetimedb::Filter::Sql("SELECT * FROM person");
"""
MODULE_CODE = MODULE_CODE_INIT + """
#[derive(SpacetimeType, Clone, Copy, PartialEq, Eq)]
pub enum PersonKind {
Student,
}
fn kind_from_string(_: String) -> PersonKind {
Student
}
fn kind_to_string(Student: PersonKind) -> &'static str {
"Student"
}
"""
MODULE_CODE_UPDATED = (
MODULE_CODE_INIT
MODULE_CODE
+ """
#[derive(SpacetimeType, Clone, Copy, PartialEq, Eq)]
pub enum PersonKind {
Student,
Professor,
}
fn kind_from_string(kind: String) -> PersonKind {
match &*kind {
"Student" => Student,
"Professor" => Professor,
_ => panic!(),
}
}
fn kind_to_string(kind: PersonKind) -> &'static str {
match kind {
Student => "Student",
Professor => "Professor",
}
}
#[spacetimedb::table(name = book, public)]
pub struct Book {
isbn: String,
@@ -129,14 +89,14 @@ const BOOK_VISIBLE: spacetimedb::Filter = spacetimedb::Filter::Sql("SELECT * FRO
logging.info("Initial publish complete")
# initial module code is already published by test framework
self.call("add_person", "Robert", "Student")
self.call("add_person", "Julie", "Student")
self.call("add_person", "Samantha", "Student")
self.call("add_person", "Robert")
self.call("add_person", "Julie")
self.call("add_person", "Samantha")
self.call("print_persons", "BEFORE")
logs = self.logs(100)
self.assertIn("BEFORE: Samantha - Student", logs)
self.assertIn("BEFORE: Julie - Student", logs)
self.assertIn("BEFORE: Robert - Student", logs)
self.assertIn("BEFORE: Samantha", logs)
self.assertIn("BEFORE: Julie", logs)
self.assertIn("BEFORE: Robert", logs)
logging.info(
"Initial operations complete, updating module without clear",
@@ -160,16 +120,16 @@ const BOOK_VISIBLE: spacetimedb::Filter = spacetimedb::Filter::Sql("SELECT * FRO
self.logs(100)
self.call("add_person", "Husserl", "Professor")
self.call("add_person", "Husserl")
self.call("add_book", "1234567890")
self.call("print_persons", "AFTER_PERSON")
self.call("print_books", "AFTER_BOOK")
logs = self.logs(100)
self.assertIn("AFTER_PERSON: Samantha - Student", logs)
self.assertIn("AFTER_PERSON: Julie - Student", logs)
self.assertIn("AFTER_PERSON: Robert - Student", logs)
self.assertIn("AFTER_PERSON: Husserl - Professor", logs)
self.assertIn("AFTER_PERSON: Samantha", logs)
self.assertIn("AFTER_PERSON: Julie", logs)
self.assertIn("AFTER_PERSON: Robert", logs)
self.assertIn("AFTER_PERSON: Husserl", logs)
self.assertIn("AFTER_BOOK: 1234567890", logs)