-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix index schema from st tables. #5145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+131
−2
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8fa8584
index alias fix on restart
Shubham8287 e2a1966
index source name change migration step
Shubham8287 147c1b6
fmt
Shubham8287 acebb71
fmt
Shubham8287 bd0ae58
Revert source name change
Shubham8287 f6ce737
use different accessor name
Shubham8287 e42b195
Merge branch 'master' into shub/fix-table-migration-index
bfops File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,4 +39,5 @@ mod sql; | |
| mod sql_connect_hook; | ||
| mod templates; | ||
| mod timestamp_route; | ||
| mod typescript_index_source_name; | ||
| mod views; | ||
105 changes: 105 additions & 0 deletions
105
crates/smoketests/tests/smoketests/typescript_index_source_name.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| use spacetimedb_smoketests::{random_string, require_local_server, require_pnpm, Smoketest}; | ||
|
|
||
| const TYPESCRIPT_MODULE_WITHOUT_NEW_COLUMNS: &str = r#"import { schema, table, t } from "spacetimedb/server"; | ||
|
|
||
| const AppUsers = table( | ||
| { name: "users", public: false }, | ||
| { | ||
| id: t.u64().primaryKey().autoInc(), | ||
| name: t.string(), | ||
| emailAddress: t.string().index("btree"), | ||
| }, | ||
| ); | ||
|
|
||
| const spacetimedb = schema({ | ||
| AppUsers, | ||
| }); | ||
| export default spacetimedb; | ||
|
|
||
| export const insert_user = spacetimedb.reducer( | ||
| { | ||
| name: t.string(), | ||
| emailAddress: t.string(), | ||
| }, | ||
| (ctx, { name, emailAddress }) => { | ||
| ctx.db.AppUsers.insert({ | ||
| id: 0n, | ||
| name, | ||
| emailAddress, | ||
| }); | ||
| }, | ||
| ); | ||
| "#; | ||
|
|
||
| const TYPESCRIPT_MODULE_WITH_NEW_COLUMNS: &str = r#"import { schema, table, t } from "spacetimedb/server"; | ||
|
|
||
| const AppUsers = table( | ||
| { name: "users", public: false }, | ||
|
joshua-spacetime marked this conversation as resolved.
|
||
| { | ||
| id: t.u64().primaryKey().autoInc(), | ||
| name: t.string(), | ||
| emailAddress: t.string().index("btree"), | ||
| age: t.number().optional().default(undefined), | ||
| isActive: t.bool().default(false).index(), | ||
| }, | ||
| ); | ||
|
|
||
| const spacetimedb = schema({ | ||
| AppUsers, | ||
| }); | ||
| export default spacetimedb; | ||
|
|
||
| export const find_user_by_email = spacetimedb.reducer( | ||
| { emailAddress: t.string() }, | ||
| (ctx, { emailAddress }) => { | ||
| let count = 0; | ||
| for (const _row of ctx.db.AppUsers.emailAddress.filter(emailAddress)) { | ||
| count += 1; | ||
| } | ||
| console.info(`matched ${count}`); | ||
| }, | ||
| ); | ||
|
|
||
| export const find_users_by_active_status = spacetimedb.reducer( | ||
| { isActive: t.bool() }, | ||
| (ctx, { isActive }) => { | ||
| let count = 0; | ||
| for (const _row of ctx.db.AppUsers.isActive.filter(isActive)) { | ||
| count += 1; | ||
| } | ||
| console.info(`matched active users ${count}`); | ||
| }, | ||
| ); | ||
| "#; | ||
|
|
||
| #[test] | ||
| fn test_typescript_add_optional_columns() { | ||
| require_pnpm!(); | ||
| require_local_server!(); | ||
|
|
||
| let mut test = Smoketest::builder().autopublish(false).build(); | ||
| let module_name = format!("typescript-add-optional-columns-{}", random_string()); | ||
|
|
||
| let database_identity = test | ||
| .publish_typescript_module_source( | ||
| "typescript-add-optional-columns-v1", | ||
| &module_name, | ||
| TYPESCRIPT_MODULE_WITHOUT_NEW_COLUMNS, | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| test.call("insert_user", &["Alice", "alice@example.com"]).unwrap(); | ||
|
|
||
| test.restart_server(); | ||
|
|
||
| test.publish_typescript_module_source_clear( | ||
| "typescript-add-optional-columns-v2", | ||
| &database_identity, | ||
| TYPESCRIPT_MODULE_WITH_NEW_COLUMNS, | ||
| false, | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| test.call("find_user_by_email", &["alice@example.com"]).unwrap(); | ||
| test.call("find_users_by_active_status", &["false"]).unwrap(); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.