-
Notifications
You must be signed in to change notification settings - Fork 420
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
feat: Add support for table column comments and to control a tables data retention and change tracking settings #614
feat: Add support for table column comments and to control a tables data retention and change tracking settings #614
Conversation
"data_retention_days": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 1, |
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.
Will this default value overwrite the inherited value from a higher level object? I believe the default behavior in snowflake is to inherit from the "higher object". For example, if I were to set data_retention_days=20
for my schema, I'd expect that to be inherited by the table. This seems like it might break that?
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 also think since the variable is called data_retention_time_in_days
we should also name it that here. https://docs.snowflake.com/en/sql-reference/parameters.html#data-retention-time-in-days
It does look like the Default
value is 1 in the docs though.
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.
More context
If a retention period is specified for a database or schema, the period is inherited by default for all objects created in the database/schema
from https://docs.snowflake.com/en/user-guide/data-time-travel.html
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.
@alldoami @berosen - I really wasn't sure what to use as snowflake_schema
has data_retention_days
and snowflake_database
has data_retention_time_in_days
so there's inconsistencies already.
https://github.com/chanzuckerberg/terraform-provider-snowflake/blob/main/pkg/resources/schema.go#L54
https://github.com/chanzuckerberg/terraform-provider-snowflake/blob/main/pkg/resources/database.go#L25
@berosen - yes you're right it will override the default from a parent object, I could change this so that if its nil then the setting is not applied to the table if that's more suitable. Which in the case of using this provider, it will be the schema as that has the logic I have here, e.g. it defaults to 1, rather than defaults to inherit.
@alldoami - I can change the behaviour of the snowflake_schema
resource too, but obviously that will have some side effects for existing deployments. I have no idea why on the database the value is computed though.
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.
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.
@berosen - I have been looking into this, and I'm not sure its possible with how the current typing system works for schema.TypeInt
- see hashicorp/terraform-plugin-sdk#261
Essentially , if I set Default to be nil
, then the SDK returns this as 0
and so there doesn't appear to be a nice way to inherit.
In addition, when reading a table with SHOW TABLES
, then even if the value was not supplied (so it inherits) then it returns the value defined in it's parent schema, so even then there is no way to detect if there is a difference.
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.
Ah ok I see your reasoning now with the naming @robbruce.
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.
@robbruce That's a good point, I think the work around for that would be complicated. Maybe it's enough to write a note in the description that the inheritance needs to be explicitly defined by passing the same value as the parent object? ie
snowflake_table foo {
...
data_retention_days=snowflake_schema.name. data_retention_days
}
Sorry for the noise all!
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.
/ok-to-test sha=b75a091 |
Integration tests success for b75a091 |
tracking table options
/ok-to-test sha=5eb437d |
Integration tests failure for 5eb437d |
/ok-to-test sha=5d770a1 |
Integration tests failure for 5d770a1 |
@alldoami - what needs to be done to sort out the integration-trusted test? |
@robbruce can you add |
@alldoami - done, and rebased with main |
/ok-to-test sha=05e036d |
Integration tests failure for 05e036d |
/ok-to-test sha=f2adee7 |
Integration tests success for f2adee7 |
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.
Woo! Nice
…ata retention and change tracking settings (Snowflake-Labs#614)
…ata retention and change tracking settings (Snowflake-Labs#614)
…ata retention and change tracking settings (Snowflake-Labs#614)
Adds the following options to the table resource
DATA_RETENTION_TIME_IN_DAYS
on a tableCHANGE_TRACKING
on a tableTest Plan
References