Skip to content

Instantly share code, notes, and snippets.

@C-ArenA
Last active March 23, 2024 20:02
Show Gist options
  • Save C-ArenA/a214747663d6b1e0d8216c072cac625a to your computer and use it in GitHub Desktop.
Save C-ArenA/a214747663d6b1e0d8216c072cac625a to your computer and use it in GitHub Desktop.
Get tables without Laravel timestamps in PostgreSQL
SELECT tables.table_name
FROM information_schema.tables as tables
LEFT JOIN(
SELECT t.table_name,
c.column_name,
c.is_nullable,
c.data_type
FROM information_schema.tables AS t
join information_schema.columns AS c ON c.table_name = t.table_name
WHERE t.table_schema = 'public'
AND c.column_name = 'created_at'
ORDER BY t.table_name
) AS timestamped_tables ON timestamped_tables.table_name = tables.table_name
WHERE tables.table_schema = 'public'
AND timestamped_tables.column_name IS NULL
AND tables.table_name NOT IN (
'migrations',
'failed_jobs',
'model_has_permissions',
'model_has_roles',
'role_has_permissions'
)
AND tables.table_name NOT LIKE 'oauth_%'
AND tables.table_name NOT LIKE 'telescope_%';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment