diff --git a/IHP/IDE/CodeGen/MigrationGenerator.hs b/IHP/IDE/CodeGen/MigrationGenerator.hs index 4992ff368..c21631b52 100644 --- a/IHP/IDE/CodeGen/MigrationGenerator.hs +++ b/IHP/IDE/CodeGen/MigrationGenerator.hs @@ -428,7 +428,7 @@ normalizeTable table@(CreateTable { .. }) = ( CreateTable { columns = fst normal Left c -> Just c normalizeConstraint :: Text -> Constraint -> Constraint -normalizeConstraint _ ForeignKeyConstraint { name, columnName, referenceTable, referenceColumn, onDelete } = ForeignKeyConstraint { name, columnName = Text.toLower columnName, referenceTable = Text.toLower referenceTable, referenceColumn = fmap Text.toLower referenceColumn, onDelete = Just (fromMaybe NoAction onDelete) } +normalizeConstraint _ ForeignKeyConstraint { name, columnName, referenceTable, referenceColumn, onDelete } = ForeignKeyConstraint { name = truncateIdentifier <$> name, columnName = Text.toLower columnName, referenceTable = Text.toLower referenceTable, referenceColumn = fmap Text.toLower referenceColumn, onDelete = Just (fromMaybe NoAction onDelete) } normalizeConstraint tableName constraint@(UniqueConstraint { name = Just uniqueName, columnNames }) | length columnNames > 1 = -- Single column UNIQUE constraints like: -- diff --git a/Test/IDE/CodeGeneration/MigrationGenerator.hs b/Test/IDE/CodeGeneration/MigrationGenerator.hs index 16c64739b..abe4ad431 100644 --- a/Test/IDE/CodeGeneration/MigrationGenerator.hs +++ b/Test/IDE/CodeGeneration/MigrationGenerator.hs @@ -1377,6 +1377,17 @@ CREATE POLICY "Users can read and edit their own record" ON public.users USING ( diffSchemas targetSchema actualSchema `shouldBe` migration + it "should truncate very long constraint names" do + let actualSchema = sql $ cs [plain| + ALTER TABLE organization_num_employees_ranges ADD CONSTRAINT organization_num_employees_ranges_ref_prospect_search_request_id FOREIGN KEY (prospect_search_request_id) REFERENCES prospect_search_requests (id) ON DELETE NO ACTION; + |] + let targetSchema = sql $ cs [plain| + ALTER TABLE organization_num_employees_ranges ADD CONSTRAINT organization_num_employees_ranges_ref_prospect_search_request_i FOREIGN KEY (prospect_search_request_id) REFERENCES prospect_search_requests (id) ON DELETE NO ACTION; + |] + let migration = [] + + diffSchemas targetSchema actualSchema `shouldBe` migration + it "should deal with nested SELECT expressions inside a policy" do let actualSchema = sql $ cs [plain| CREATE POLICY "Allow users to see their own company" ON public.companies USING ((id = ( SELECT users.company_id