Hey guys, I’m getting this error: ```Stack franci...
# help
f
Hey guys, I’m getting this error:
Copy code
Stack francis-alloy-one-StorageStack
  Status: failed
  Error: francis-sst-one-orders already exists
Is there a way that it wont error everytime I start and stop my SST?
f
@outaTiME thanks. Will read up
@outaTiME seems like it’s the same issue with the poster below. Something to do with the DynamoDB Table created alread
o
the issue is that the resource probably exists because in SST v1.x the default name of the stack changes (the case more specifically) so when you build a new deploy there are two stacks with the same internal resource names
so if you want to avoid that error you should probably make your stack name the same as it was before the SST version update
f
@outaTiME it’s my first time using SST, so I’m starting with version 1.
t
This shouldn't be happening every time you start and stop sst
Are you removing stacks?
f
@thdxr nope. It’s the same one added to
.stack(StorageStack)
t
Can you share what the stack looks like
f
Copy code
import { StackContext, Table } from "@serverless-stack/resources";

export function StorageStack(ctx: StackContext) {
  const appsTable = new Table(ctx.stack, "apps", {
    fields: {
      appId: "string",
      name: "string",
    },
    primaryIndex: { partitionKey: "appId", sortKey: "name" },
  });

  // Main Table
  const storesTable = new Table(ctx.stack, "stores", {
    fields: {
      storeId: "string",
      url: "string",
      defaultCurrency: "string",
      storeName: "string",
    },
    primaryIndex: { partitionKey: "storeId", sortKey: "storeName" },
  });

  const customersTable = new Table(ctx.stack, "customers", {
    fields: {
      customerId: "string",
      storeId: "string",
      createdAt: "string",
    },
    primaryIndex: { partitionKey: "storeId", sortKey: "createdAt" },
  });

  // Pivot Table
  const customersOrdersTable = new Table(ctx.stack, "customers_orders", {
    fields: {
      storeId: "string",
      customerId: "string",
      orderId: "string",
    },
    primaryIndex: { partitionKey: "storeId", sortKey: "customerId" },
  });

  const fulfillmentsTable = new Table(ctx.stack, "fulfillments", {
    fields: {
      fulfillmentId: "string",
      storeId: "string",
      orderId: "string",
    },
    primaryIndex: { partitionKey: "storeId", sortKey: "orderId" },
  });

  const ordersTable = new Table(ctx.stack, "orders", {
    fields: {
      orderId: "string",
      storeId: "string",
      appId: "string",
      orderNumber: "string",
    },
    primaryIndex: { partitionKey: "storeId", sortKey: "orderNumber" },
  });

  const payoutsTable = new Table(ctx.stack, "payouts", {
    fields: {
      payoutId: "string",
      storeId: "string",
      status: "string",
    },
    primaryIndex: { partitionKey: "storeId", sortKey: "status" },
  });

  const productsTable = new Table(ctx.stack, "products", {
    fields: {
      productId: "string",
      storeId: "string",
      appId: "string",
      name: "string",
    },
    primaryIndex: { partitionKey: "storeId", sortKey: "name" },
  });

  const productVariantsTable = new Table(ctx.stack, "productVariants", {
    fields: {
      variantId: "string",
      storeId: "string",
      title: "string",
    },
    primaryIndex: { partitionKey: "storeId", sortKey: "title" },
  });

  // Pivot Table
  const productsProductVariantsTable = new Table(
    ctx.stack,
    "products_productVariants",
    {
      fields: {
        storeId: "string",
        productId: "string",
        variantId: "string",
      },
      primaryIndex: { partitionKey: "storeId", sortKey: "productId" },
    }
  );

  const transactionsTable = new Table(ctx.stack, "transactions", {
    fields: {
      transactionId: "string",
      storeId: "string",
      orderId: "string",
    },
    primaryIndex: { partitionKey: "storeId", sortKey: "orderId" },
  });

  return {
    appsTable,
    customersTable,
    fulfillmentsTable,
    ordersTable,
    payoutsTable,
    productsTable,
    productVariantsTable,
    storesTable,
    transactionsTable,
    customersOrdersTable,
    productsProductVariantsTable,
  };
}
Does this happen is I do changes to the
ordersTable
? Like add or remove fields?
t
few things 1. Some changes to DynamoDB require a replacement. So it'll try to create a new table, think changes to the primary index 2. Are you new to DynamoDB? It's quite different than a sql database and your data model here is going to be hard to work with. I really only have one table for my whole application because I follow DDB single table design. There's a library called ElectroDB that helps you implement this, I suggest looking more into it
f
Yes, I am new to DynamoDB
t
If you follow 2, you'll never really have to make changes to DynamoDB
f
I see.
I came from a relational database background
t
Yeah most people do! DDB is very different and requires unlearning some RDBMS patterns
If using it correctly your stacks code rarely needs to be updated because it only contains a few fixed fields and the specifics are managed in your application
f
Gotta read up more on DDB!
Thank you so much! At least these problems teach me things.
t
If you want a whole book Alex debrie dynamo db book is great
Otherwise read a bit about single table design and then watch Rick houllihan videos on YouTube where he does real life modeling

https://www.youtube.com/watch?v=Xn12QSNa4RE&t=1382s

f
Thanks @thdxr ! Will redesign my tables with this in mind.
g
Alex DeBrie is another person on YouTube to watch and learn about Single Table Design in DynamoDB. It will change the way you think about storing and accessing data