@@ -275,9 +275,10 @@ func (ac *AdminClient) Tables(ctx context.Context) ([]string, error) {
275275// disable change stream retention.
276276type ChangeStreamRetention optional.Duration
277277
278- // DeletionProtection indicates whether the table is protected against data loss
279- // i.e. when set to protected, deleting the table, the column families in the table,
280- // and the instance containing the table would be prohibited.
278+ // DeletionProtection indicates whether the table, authorized view, logical view or
279+ // materialized view is protected against data loss i.e. when set to protected,
280+ // deleting the view, the table, the column families in the table,
281+ // and the instance containing the table or view would be prohibited.
281282type DeletionProtection int
282283
283284// None indicates that deletion protection is unset
@@ -3123,13 +3124,25 @@ func (iac *InstanceAdminClient) CreateLogicalView(ctx context.Context, instanceI
31233124 return errors .New ("LogicalViewID is required" )
31243125 }
31253126
3127+ lv := & btapb.LogicalView {
3128+ Query : conf .Query ,
3129+ }
3130+ if conf .DeletionProtection != None {
3131+ switch dp := conf .DeletionProtection ; dp {
3132+ case Protected :
3133+ lv .DeletionProtection = true
3134+ case Unprotected :
3135+ lv .DeletionProtection = false
3136+ default :
3137+ break
3138+ }
3139+ }
3140+
31263141 ctx = mergeOutgoingMetadata (ctx , iac .md )
31273142 req := & btapb.CreateLogicalViewRequest {
31283143 Parent : instancePrefix (iac .project , instanceID ),
31293144 LogicalViewId : conf .LogicalViewID ,
3130- LogicalView : & btapb.LogicalView {
3131- Query : conf .Query ,
3132- },
3145+ LogicalView : lv ,
31333146 }
31343147
31353148 op , err := iac .iClient .CreateLogicalView (ctx , req )
@@ -3144,7 +3157,8 @@ func (iac *InstanceAdminClient) CreateLogicalView(ctx context.Context, instanceI
31443157type LogicalViewInfo struct {
31453158 LogicalViewID string
31463159
3147- Query string
3160+ Query string
3161+ DeletionProtection DeletionProtection
31483162}
31493163
31503164// LogicalViewInfo retrieves information about a logical view.
@@ -3165,7 +3179,13 @@ func (iac *InstanceAdminClient) LogicalViewInfo(ctx context.Context, instanceID,
31653179 if err != nil {
31663180 return nil , err
31673181 }
3168- return & LogicalViewInfo {LogicalViewID : strings .TrimPrefix (res .Name , prefix + "/logicalViews/" ), Query : res .Query }, nil
3182+ lv := & LogicalViewInfo {LogicalViewID : strings .TrimPrefix (res .Name , prefix + "/logicalViews/" ), Query : res .Query }
3183+ if res .DeletionProtection {
3184+ lv .DeletionProtection = Protected
3185+ } else {
3186+ lv .DeletionProtection = Unprotected
3187+ }
3188+ return lv , nil
31693189}
31703190
31713191// LogicalViews returns a list of the logical views in the instance.
@@ -3185,8 +3205,14 @@ func (iac *InstanceAdminClient) LogicalViews(ctx context.Context, instanceID str
31853205 return nil , err
31863206 }
31873207
3188- for _ , lv := range res .LogicalViews {
3189- views = append (views , LogicalViewInfo {LogicalViewID : strings .TrimPrefix (lv .Name , prefix + "/logicalViews/" ), Query : lv .Query })
3208+ for _ , lView := range res .LogicalViews {
3209+ lv := LogicalViewInfo {LogicalViewID : strings .TrimPrefix (lView .Name , prefix + "/logicalViews/" ), Query : lView .Query }
3210+ if lView .DeletionProtection {
3211+ lv .DeletionProtection = Protected
3212+ } else {
3213+ lv .DeletionProtection = Unprotected
3214+ }
3215+ views = append (views , lv )
31903216 }
31913217 return views , nil
31923218}
@@ -3207,6 +3233,17 @@ func (iac *InstanceAdminClient) UpdateLogicalView(ctx context.Context, instanceI
32073233 updateMask .Paths = append (updateMask .Paths , "query" )
32083234 lv .Query = conf .Query
32093235 }
3236+ if conf .DeletionProtection != None {
3237+ updateMask .Paths = append (updateMask .Paths , "deletion_protection" )
3238+ switch dp := conf .DeletionProtection ; dp {
3239+ case Protected :
3240+ lv .DeletionProtection = true
3241+ case Unprotected :
3242+ lv .DeletionProtection = false
3243+ default :
3244+ break
3245+ }
3246+ }
32103247 req := & btapb.UpdateLogicalViewRequest {
32113248 LogicalView : lv ,
32123249 UpdateMask : updateMask ,
0 commit comments