Localisation updates from https://translatewiki.net.
[lhc/web/wiklou.git] / maintenance / mssql / archives / patch-archive-drop-fks.sql
1 DECLARE @base nvarchar(max),
2 @SQL nvarchar(max),
3 @id sysname;--
4
5 SET @base = 'ALTER TABLE /*_*/archive DROP CONSTRAINT ';--
6
7 SELECT @id = fk.name
8 FROM sys.foreign_keys fk
9 JOIN sys.foreign_key_columns fkc
10 ON fkc.constraint_object_id = fk.object_id
11 JOIN sys.columns c
12 ON c.column_id = fkc.parent_column_id
13 AND c.object_id = fkc.parent_object_id
14 WHERE
15 fk.parent_object_id = OBJECT_ID('/*_*/archive')
16 AND fk.referenced_object_id = OBJECT_ID('/*_*/revision')
17 AND c.name = 'ar_parent_id';--
18
19 SET @SQL = @base + @id;--
20
21 EXEC sp_executesql @SQL;--
22
23 -- while we're at it, let's fix up the other foreign key constraints on archive
24 -- as future patches touch constraints on other tables, they'll take the time to update constraint names there as well
25 SELECT @id = fk.name
26 FROM sys.foreign_keys fk
27 JOIN sys.foreign_key_columns fkc
28 ON fkc.constraint_object_id = fk.object_id
29 JOIN sys.columns c
30 ON c.column_id = fkc.parent_column_id
31 AND c.object_id = fkc.parent_object_id
32 WHERE
33 fk.parent_object_id = OBJECT_ID('/*_*/archive')
34 AND fk.referenced_object_id = OBJECT_ID('/*_*/mwuser')
35 AND c.name = 'ar_user';--
36
37 SET @SQL = @base + @id;--
38
39 EXEC sp_executesql @SQL;--
40
41 ALTER TABLE /*_*/archive ADD CONSTRAINT ar_user__user_id__fk FOREIGN KEY (ar_user) REFERENCES /*_*/mwuser(user_id);--
42
43 SELECT @id = fk.name
44 FROM sys.foreign_keys fk
45 JOIN sys.foreign_key_columns fkc
46 ON fkc.constraint_object_id = fk.object_id
47 JOIN sys.columns c
48 ON c.column_id = fkc.parent_column_id
49 AND c.object_id = fkc.parent_object_id
50 WHERE
51 fk.parent_object_id = OBJECT_ID('/*_*/archive')
52 AND fk.referenced_object_id = OBJECT_ID('/*_*/text')
53 AND c.name = 'ar_text_id';--
54
55 SET @SQL = @base + @id;--
56
57 EXEC sp_executesql @SQL;--
58
59 ALTER TABLE /*_*/archive ADD CONSTRAINT ar_text_id__old_id__fk FOREIGN KEY (ar_text_id) REFERENCES /*_*/text(old_id) ON DELETE CASCADE;