feat: ability to create a project #9
							
								
								
									
										9
									
								
								diesel.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								diesel.toml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
# For documentation on how to configure this file,
 | 
			
		||||
# see https://diesel.rs/guides/configuring-diesel-cli
 | 
			
		||||
 | 
			
		||||
[print_schema]
 | 
			
		||||
file = "src/schema.rs"
 | 
			
		||||
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]
 | 
			
		||||
 | 
			
		||||
[migrations_directory]
 | 
			
		||||
dir = "/home/matous/Documents/todo-baggins/migrations"
 | 
			
		||||
							
								
								
									
										6
									
								
								migrations/00000000000000_diesel_initial_setup/down.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								migrations/00000000000000_diesel_initial_setup/down.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
-- This file was automatically created by Diesel to setup helper functions
 | 
			
		||||
-- and other internal bookkeeping. This file is safe to edit, any future
 | 
			
		||||
-- changes will be added to existing projects as new migrations.
 | 
			
		||||
 | 
			
		||||
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
 | 
			
		||||
DROP FUNCTION IF EXISTS diesel_set_updated_at();
 | 
			
		||||
							
								
								
									
										36
									
								
								migrations/00000000000000_diesel_initial_setup/up.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								migrations/00000000000000_diesel_initial_setup/up.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
-- This file was automatically created by Diesel to setup helper functions
 | 
			
		||||
-- and other internal bookkeeping. This file is safe to edit, any future
 | 
			
		||||
-- changes will be added to existing projects as new migrations.
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 | 
			||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- Sets up a trigger for the given table to automatically set a column called
 | 
			
		||||
-- `updated_at` whenever the row is modified (unless `updated_at` was included
 | 
			
		||||
-- in the modified columns)
 | 
			
		||||
--
 | 
			
		||||
-- # Example
 | 
			
		||||
--
 | 
			
		||||
-- ```sql
 | 
			
		||||
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
 | 
			
		||||
--
 | 
			
		||||
-- SELECT diesel_manage_updated_at('users');
 | 
			
		||||
-- ```
 | 
			
		||||
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
 | 
			
		||||
BEGIN
 | 
			
		||||
    EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
 | 
			
		||||
                    FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
 | 
			
		||||
END;
 | 
			
		||||
$$ LANGUAGE plpgsql;
 | 
			
		||||
					
	
	
	
	
	
	
	
	
 Ensure usage of  The  Analysis chainEnsure proper usage of the  The function  Scripts executedThe following scripts were executed for the analysis: Script: Length of output: 148 Script: Length of output: 4075 > [!TIP]
> Codebase Verification
**Ensure usage of `diesel_manage_updated_at` function for automatic updates.**
The `diesel_manage_updated_at` function is not actively used in the migration files to set up triggers for automatic updates to the `updated_at` column. Please ensure that this function is called for each table that requires this functionality. 
<details>
<summary>Analysis chain</summary>
**Ensure proper usage of the `diesel_manage_updated_at` function.**
The function `diesel_manage_updated_at` is designed to set up a trigger for automatically updating the `updated_at` column. Make sure that this function is called for each table that requires this functionality.
</details>
<details>
<summary>Scripts executed</summary>
The following scripts were executed for the analysis:
Script:
```shell
#!/bin/bash
# Description: Verify that `diesel_manage_updated_at` is used for each table requiring automatic `updated_at` updates.
# Test: Search for the function usage across the SQL migration files.
rg --type sql $'SELECT diesel_manage_updated_at'
```
Length of output: 148
---
Script:
```shell
#!/bin/bash
# Description: Search for active (uncommented) usage of the `diesel_manage_updated_at` function in SQL migration files.
rg --type sql 'diesel_manage_updated_at' --invert-match --fixed-strings '--'
```
Length of output: 4075
</details>
<!-- This is an auto-generated comment by CodeRabbit --> 
			
			
		 | 
			||||
 | 
			
		||||
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
 | 
			
		||||
BEGIN
 | 
			
		||||
    IF (
 | 
			
		||||
        NEW IS DISTINCT FROM OLD AND
 | 
			
		||||
        NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
 | 
			
		||||
    ) THEN
 | 
			
		||||
        NEW.updated_at := current_timestamp;
 | 
			
		||||
    END IF;
 | 
			
		||||
    RETURN NEW;
 | 
			
		||||
END;
 | 
			
		||||
$$ LANGUAGE plpgsql;
 | 
			
		||||
		Reference in New Issue
	
	Block a user
	
Clarify the auto-generated nature of the file.
The comments indicate that this file was automatically created by Diesel. Ensure that any manual edits are documented to avoid confusion in future migrations.