@@ -8,7 +8,7 @@ def analyze
88 notes . concat ( analyze_timestamps )
99 notes . concat ( analyze_soft_deletes )
1010 notes . concat ( analyze_sti_columns )
11- notes . concat ( analyze_naming_conventions )
11+ notes . concat ( analyze_large_text_columns )
1212 notes
1313 end
1414
@@ -17,63 +17,38 @@ def analyze
1717 def analyze_timestamps
1818 notes = [ ]
1919
20- notes << 'Missing timestamp columns (created_at, updated_at)' unless has_timestamps?
20+ notes << NoteCodes :: NO_TIMESTAMPS unless has_timestamps?
2121
2222 if has_column? ( 'created_at' ) && !has_column? ( 'updated_at' )
23- notes << 'Has created_at but missing updated_at'
23+ notes << NoteCodes :: PARTIAL_TS
2424 elsif !has_column? ( 'created_at' ) && has_column? ( 'updated_at' )
25- notes << 'Has updated_at but missing created_at'
25+ notes << NoteCodes :: PARTIAL_TS
2626 end
2727
2828 notes
2929 end
3030
3131 def analyze_soft_deletes
32- notes = [ ]
33-
34- soft_delete_columns . each do |column |
35- notes << "Soft delete column '#{ column . name } ' should be indexed" unless indexed? ( column )
32+ soft_delete_columns . reject { |col | indexed? ( col ) } . map do |column |
33+ NoteCodes . note ( column . name , NoteCodes ::INDEX )
3634 end
37-
38- notes
3935 end
4036
4137 def analyze_sti_columns
4238 notes = [ ]
4339
4440 if sti_model? && type_column
45- notes << "STI type column '#{ type_column . name } ' should be indexed" unless indexed? ( type_column )
46-
47- notes << "STI type column '#{ type_column . name } ' should have NOT NULL constraint" if type_column . null
41+ notes << NoteCodes . note ( type_column . name , NoteCodes ::INDEX ) unless indexed? ( type_column )
42+ notes << NoteCodes . note ( type_column . name , NoteCodes ::STI_NOT_NULL ) if type_column . null
4843 end
4944
5045 notes
5146 end
5247
53- def analyze_naming_conventions
54- notes = [ ]
55-
56- # Check for non-conventional column names
57- columns . each do |column |
58- if column . name . match? ( /^(is|has)_/i )
59- notes << "Column '#{ column . name } ' uses non-conventional prefix - consider removing 'is_' or 'has_'"
60- end
61-
62- if column . name . match? ( /Id$/ ) # Capital I
63- notes << "Column '#{ column . name } ' should use snake_case (e.g., '#{ column . name . underscore } ')"
64- end
65- end
66-
67- # Check table naming
68- # Extract the actual table name without schema prefix for PostgreSQL
69- # PostgreSQL uses schema.table format (e.g., "ai.skills" -> "skills")
70- unqualified_table = table_name . to_s . split ( '.' ) . last
71-
72- if !unqualified_table . match? ( /^[a-z_]+$/ ) || unqualified_table != unqualified_table . pluralize
73- notes << "Table name '#{ table_name } ' doesn't follow Rails conventions (should be plural, snake_case)"
48+ def analyze_large_text_columns
49+ columns . select { |c | c . type == :text } . map do |column |
50+ NoteCodes . note ( column . name , NoteCodes ::STORAGE )
7451 end
75-
76- notes
7752 end
7853
7954 def has_timestamps?
0 commit comments