-
Notifications
You must be signed in to change notification settings - Fork 1
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
Bulk table import #272
Bulk table import #272
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@joewagner @asutula i had to import 143 DIMO tables into the Studio, so i ended up creating a command to help me do it. you can find all of the tables here: https://studio.tableland.xyz/partners/dimo idk if this command something we actually want to add, so I've just kept it in draft as a reference. for example, the tRPC / API could probably handle this more efficiently and batch calls. a few notes:
and a couple of issues with the API:
here's the 500 error:
|
} | ||
|
||
export const command = "import-tables <file> [sanitize]"; | ||
export const desc = wrapText( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: i created this helper bc i couldnt get the yargs help command's formatting to print properly
definitionName || helpers.getPrefixFromTableName(tableName); | ||
// Ensure custom definition name is valid | ||
try { | ||
await defNameSchema.parseAsync(defName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i needed this method from the studio-validators
package to check if the user-defined table def name was usable.
and below this is where i do the "sanitize" step that may or may not be useful in the generalized use case...but it was for me w/ DIMO!
export * from "./validators/projects"; | ||
export * from "./validators/auth"; | ||
export * from "./validators/tables"; | ||
export { defNameSchema } from "./common.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lastly, i had to add the .js
extension to make this work with the CLI
We already have a command for importing tables. I've been trying to avoid having two commands that do the same thing and only differ by being plural or not. Curios if this makes sense to others, but maybe we refactor so that the command can take a file as input or use command parameters? Alternatively a more different name might make sense? |
argv.description, | ||
"definition description is required", | ||
); | ||
const projectId = helpers.getStringValue( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: i dropped this from being a positional since it's already a global flag. thus, this command can use the context, if set, vs explicitly being passed
b31024d
to
e76df18
Compare
@joewagner so i removed the duplicate-ish commands and consolidated them into a single
and
fwiw, i thought about also including the |
btw, getting an error for the
someone noted issues with the NODE_ENV var, so if i put
|
@dtbuchholz I am getting the same TypeError: Cannot read properties of null (reading 'useContext') error, I'll try modifying NODE_ENV fwiw, the original issue with node modules seems to be originating with the |
Next's prerender error explanation page barely unhelpful. Basically they suggest that you review the entire code base for one of 8 errors that might be the problem. |
I remember running into this exact issue when I started the ethers refactor. I was trying out different It might've been a |
@dtbuchholz I got the package-lock issues in #266 worked out, but I think you'll want to undo the changes you made to package-lock then rebase this on top of my most recent commit. |
e76df18
to
3f5c6b1
Compare
3f5c6b1
to
9c0200e
Compare
pull_request: | ||
branches: ["main", "staging"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joewagner wait...was i supposed to remove this line? i can't remember / find the original comment about this GH workflow change.
should it be: branches: ["main"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added new testfile for table imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, and is a really nice feature. The only issue I was having is with the definitionName
not being optional.
I'm ok if we want to require the header, but if that's the case we should update the help text
const rows = dataObject.slice(1); | ||
// Must be CSV file and have headers in the order: `tableName`, | ||
// `description`, and `definitionName` (optional) | ||
if (headers.length < 3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried modifying an import file to do the import without definitionName, but I can't get it to work.
If I remove the header, it doesn't pass this check.
If I remove the values, I get a zod error that says "String must contain at least 1 character(s)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joewagner good catch, fixed and added a couple more tests for this.
a random callout—i'm not enforcing the actual csv headers to be of a specific naming convention but only to have correct ordering. i think that's fine, right? i.e., your headers could be blah,blah,blah
, but we just care that those are tableName,description,definitionName
in terms of the actual values (where definitionName
is actually optional, now).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joewagner good catch, fixed and added a couple more tests for this.
Excellent!
a random callout—i'm not enforcing the actual csv headers to be of a specific naming convention but only to have correct ordering. i think that's fine, right? i.e., your headers could be
blah,blah,blah
, but we just care that those aretableName,description,definitionName
in terms of the actual values (wheredefinitionName
is actually optional, now).
That seems fine, if anyone has an issue we can re-evaluate.
This isnt necessarily the best design but a starting point. For example, it might make sense to combine this with the singular `import-table` and have a `--bulk` flag or something. Or, maybe keeping them separate is ideal.
Rather than having multiple table import commands, this consolidates them into one. You can either `import table` or `import bulk` to import a single table or a series of them under the same parent.
0b03782
to
8767691
Compare
(note: tests pass, aside from the known nonce tests issue) |
Perfect, I'm re-running now. |
Summary
import table
andimport bulk
@tableland/validators
to help with checking if table definition names in CSV are valid.main
and no longer usestaging
.Details
studio import table <args>
for a single table—which is the same as the oldimport-table
command.import bulk <file> [--sanitize]
lets you pass a CSV file table name, description, and new def name. The sanitize command will clean the new def names up for you, which is useful in case you have a lot of tables and are unsure why your def name isn't letting you import tables.