@@ -511,11 +511,6 @@ func (rwt *crdbReadWriteTXN) LegacyWriteNamespaces(ctx context.Context, newConfi
511511 return fmt .Errorf (errUnableToWriteConfig , err )
512512 }
513513
514- // Write the schema hash to the schema_revision table for fast lookups
515- if err := rwt .writeLegacySchemaHash (ctx ); err != nil {
516- return fmt .Errorf ("failed to write schema hash: %w" , err )
517- }
518-
519514 return nil
520515}
521516
@@ -571,11 +566,6 @@ func (rwt *crdbReadWriteTXN) LegacyDeleteNamespaces(ctx context.Context, nsNames
571566 rwt .relCountChange -= numRowsDeleted
572567 }
573568
574- // Write the schema hash to the schema_revision table for fast lookups
575- if err := rwt .writeLegacySchemaHash (ctx ); err != nil {
576- return fmt .Errorf ("failed to write schema hash: %w" , err )
577- }
578-
579569 return nil
580570}
581571
@@ -634,20 +624,53 @@ func (w *crdbSchemaWriter) writeSchemaHash(ctx context.Context, schema *core.Sto
634624 return nil
635625}
636626
637- // writeLegacySchemaHash writes the schema hash to the schema_revision table by generating
638- // the schema from current legacy namespaces and caveats
639- func (rwt * crdbReadWriteTXN ) writeLegacySchemaHash (ctx context.Context ) error {
640- // Read all namespaces and caveats
641- namespaces , err := rwt .LegacyListAllNamespaces (ctx )
642- if err != nil {
643- return fmt .Errorf ("failed to list namespaces: %w" , err )
627+ // ReadStoredSchema implements datastore.SingleStoreSchemaReader to satisfy DualSchemaReader interface requirements
628+ func (w * crdbSchemaWriter ) ReadStoredSchema (ctx context.Context ) (* core.StoredSchema , error ) {
629+ // Create a revision-aware executor that applies AS OF SYSTEM TIME
630+ // Within a transaction, we don't use AS OF SYSTEM TIME, so pass empty atSpecificRevision
631+ executor := & revisionAwareExecutor {
632+ query : w .rwt .query ,
633+ addFromToQuery : w .rwt .addFromToQuery ,
634+ assertAsOfSysTime : w .rwt .assertHasExpectedAsOfSystemTime ,
644635 }
645636
646- caveats , err := rwt .LegacyListAllCaveats (ctx )
647- if err != nil {
648- return fmt .Errorf ("failed to list caveats: %w" , err )
649- }
637+ // Use the shared schema reader/writer to read the schema
638+ // Pass empty string to bypass cache (transaction read)
639+ return w .rwt .schemaReaderWriter .ReadSchema (ctx , executor , nil , datastore .NoSchemaHashInTransaction )
640+ }
641+
642+ // LegacyWriteNamespaces delegates to the underlying transaction
643+ func (w * crdbSchemaWriter ) LegacyWriteNamespaces (ctx context.Context , newConfigs ... * core.NamespaceDefinition ) error {
644+ return w .rwt .LegacyWriteNamespaces (ctx , newConfigs ... )
645+ }
646+
647+ // LegacyDeleteNamespaces delegates to the underlying transaction
648+ func (w * crdbSchemaWriter ) LegacyDeleteNamespaces (ctx context.Context , nsNames []string , delOption datastore.DeleteNamespacesRelationshipsOption ) error {
649+ return w .rwt .LegacyDeleteNamespaces (ctx , nsNames , delOption )
650+ }
651+
652+ // LegacyLookupNamespacesWithNames delegates to the underlying transaction
653+ func (w * crdbSchemaWriter ) LegacyLookupNamespacesWithNames (ctx context.Context , nsNames []string ) ([]datastore.RevisionedDefinition [* core.NamespaceDefinition ], error ) {
654+ return w .rwt .LegacyLookupNamespacesWithNames (ctx , nsNames )
655+ }
656+
657+ // LegacyWriteCaveats delegates to the underlying transaction
658+ func (w * crdbSchemaWriter ) LegacyWriteCaveats (ctx context.Context , caveats []* core.CaveatDefinition ) error {
659+ return w .rwt .LegacyWriteCaveats (ctx , caveats )
660+ }
661+
662+ // LegacyDeleteCaveats delegates to the underlying transaction
663+ func (w * crdbSchemaWriter ) LegacyDeleteCaveats (ctx context.Context , names []string ) error {
664+ return w .rwt .LegacyDeleteCaveats (ctx , names )
665+ }
650666
667+ // WriteLegacySchemaHashFromDefinitions implements datastore.LegacySchemaHashWriter
668+ func (w * crdbSchemaWriter ) WriteLegacySchemaHashFromDefinitions (ctx context.Context , namespaces []datastore.RevisionedNamespace , caveats []datastore.RevisionedCaveat ) error {
669+ return w .rwt .writeLegacySchemaHashFromDefinitions (ctx , namespaces , caveats )
670+ }
671+
672+ // writeLegacySchemaHashFromDefinitions writes the schema hash computed from the given definitions
673+ func (rwt * crdbReadWriteTXN ) writeLegacySchemaHashFromDefinitions (ctx context.Context , namespaces []datastore.RevisionedNamespace , caveats []datastore.RevisionedCaveat ) error {
651674 // Build schema definitions list
652675 definitions := make ([]compiler.SchemaDefinition , 0 , len (namespaces )+ len (caveats ))
653676 for _ , ns := range namespaces {
@@ -689,46 +712,6 @@ func (rwt *crdbReadWriteTXN) writeLegacySchemaHash(ctx context.Context) error {
689712 return nil
690713}
691714
692- // ReadStoredSchema implements datastore.SingleStoreSchemaReader to satisfy DualSchemaReader interface requirements
693- func (w * crdbSchemaWriter ) ReadStoredSchema (ctx context.Context ) (* core.StoredSchema , error ) {
694- // Create a revision-aware executor that applies AS OF SYSTEM TIME
695- // Within a transaction, we don't use AS OF SYSTEM TIME, so pass empty atSpecificRevision
696- executor := & revisionAwareExecutor {
697- query : w .rwt .query ,
698- addFromToQuery : w .rwt .addFromToQuery ,
699- assertAsOfSysTime : w .rwt .assertHasExpectedAsOfSystemTime ,
700- }
701-
702- // Use the shared schema reader/writer to read the schema
703- // Pass empty string to bypass cache (transaction read)
704- return w .rwt .schemaReaderWriter .ReadSchema (ctx , executor , nil , datastore .NoSchemaHashInTransaction )
705- }
706-
707- // LegacyWriteNamespaces delegates to the underlying transaction
708- func (w * crdbSchemaWriter ) LegacyWriteNamespaces (ctx context.Context , newConfigs ... * core.NamespaceDefinition ) error {
709- return w .rwt .LegacyWriteNamespaces (ctx , newConfigs ... )
710- }
711-
712- // LegacyDeleteNamespaces delegates to the underlying transaction
713- func (w * crdbSchemaWriter ) LegacyDeleteNamespaces (ctx context.Context , nsNames []string , delOption datastore.DeleteNamespacesRelationshipsOption ) error {
714- return w .rwt .LegacyDeleteNamespaces (ctx , nsNames , delOption )
715- }
716-
717- // LegacyLookupNamespacesWithNames delegates to the underlying transaction
718- func (w * crdbSchemaWriter ) LegacyLookupNamespacesWithNames (ctx context.Context , nsNames []string ) ([]datastore.RevisionedDefinition [* core.NamespaceDefinition ], error ) {
719- return w .rwt .LegacyLookupNamespacesWithNames (ctx , nsNames )
720- }
721-
722- // LegacyWriteCaveats delegates to the underlying transaction
723- func (w * crdbSchemaWriter ) LegacyWriteCaveats (ctx context.Context , caveats []* core.CaveatDefinition ) error {
724- return w .rwt .LegacyWriteCaveats (ctx , caveats )
725- }
726-
727- // LegacyDeleteCaveats delegates to the underlying transaction
728- func (w * crdbSchemaWriter ) LegacyDeleteCaveats (ctx context.Context , names []string ) error {
729- return w .rwt .LegacyDeleteCaveats (ctx , names )
730- }
731-
732715// LegacyReadCaveatByName delegates to the underlying transaction
733716func (w * crdbSchemaWriter ) LegacyReadCaveatByName (ctx context.Context , name string ) (* core.CaveatDefinition , datastore.Revision , error ) {
734717 return w .rwt .LegacyReadCaveatByName (ctx , name )
0 commit comments