Skip to content

Commit

Permalink
Fixed SQl column sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzsantos committed Oct 15, 2024
1 parent 9d20af9 commit 94a3cc8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
29 changes: 16 additions & 13 deletions iac/AzureSQLServer-Seed.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
-- noinspection SqlDialectInspectionForFile
-- Note: We are deliberately defining most columns (in most of the read-model tables) as "string nvarchar(max)", and only specifically using other datatypes, where we know they are very un-likely to change over time.
-- We are deliberately defining most columns as NULL for the same reason. To avoid, as much as possible, having to make changes to the schema in the future, when the code changes.
-- Most read-model columns will change from string to JSON(ValueObject) as things change in your domain models, so limiting them too early to specific datatypes can backfire later on in production workloads.
-- If you want to be more specific and want to optimize column design early, you need to be very careful not to change the code in the future.
-- We recommend optimizing for change, rather than for performance, until your product has matured and fully developed, or has scaled dramatically.
-- Clearly there are limits to this, so this strategy is simply minimizing them, since we don't care at this stage about optimizing SQL storage in the cloud (i.e. no longer depend on spinning hard disks, tracks and sectors).
-- "nvarchar(max)" is used as a default for all string fields to allow for future expansion of the data model without having to change the schema. You are free to modify that limit (across the board) at your will.
-- Some columns with indexes cannot be nvarchar(max) because of the index size limit of 900 bytes.

USE
[SaaStack]
Expand Down Expand Up @@ -204,14 +212,14 @@ CREATE INDEX UserId

CREATE TABLE [dbo].[AuthToken]
(
[Id] [nvarchar](100) NOT NULL,
[LastPersistedAtUtc] [datetime] NULL,
[IsDeleted] [bit] NULL,
[AccessToken] [nvarchar](450) NULL,
[AccessTokenExpiresOn] [datetime] NULL,
[RefreshToken] [nvarchar](450) NULL,
[RefreshTokenExpiresOn] [datetime] NULL,
[UserId] [nvarchar](100) NULL,
[Id] [nvarchar](100) NOT NULL,
[LastPersistedAtUtc] [datetime] NULL,
[IsDeleted] [bit] NULL,
[AccessToken] [nvarchar](4000) NULL,
[AccessTokenExpiresOn] [datetime] NULL,
[RefreshToken] [nvarchar](4000) NULL,
[RefreshTokenExpiresOn] [datetime] NULL,
[UserId] [nvarchar](100) NULL,
) ON [PRIMARY]
GO

Expand All @@ -220,11 +228,6 @@ CREATE INDEX Id
(
[Id]
);
CREATE INDEX RefreshToken
ON [dbo].[AuthToken]
(
[RefreshToken]
);
CREATE INDEX UserId
ON [dbo].[AuthToken]
(
Expand Down
3 changes: 3 additions & 0 deletions src/.idea/.idea.SaaStack/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 94a3cc8

Please sign in to comment.