commit
						0398544a51
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -2,3 +2,5 @@ | |||||||
| .dbeaver-data-sources.xml | .dbeaver-data-sources.xml | ||||||
| .project | .project | ||||||
| Scripts/ | Scripts/ | ||||||
|  | *.log | ||||||
|  | *.swp | ||||||
|  | |||||||
| @ -7,70 +7,76 @@ | |||||||
|         "{Post Date}", |         "{Post Date}", | ||||||
|         "{Description}" |         "{Description}" | ||||||
|     ], |     ], | ||||||
|     "schemas": { |     "schemas": [ | ||||||
|         "default": [ |         { | ||||||
|             { |             "name": "default", | ||||||
|                 "path": "{Trans. Date}", |             "columns": [ | ||||||
|                 "type": "date", |                 { | ||||||
|                 "column_name": "Trans. Date" |                     "path": "{Trans. Date}", | ||||||
|             }, |                     "type": "date", | ||||||
|             { |                     "column_name": "Trans. Date" | ||||||
|                 "path": "{Post Date}", |                 }, | ||||||
|                 "type": "date", |                 { | ||||||
|                 "column_name": "Post Date" |                     "path": "{Post Date}", | ||||||
|             }, |                     "type": "date", | ||||||
|             { |                     "column_name": "Post Date" | ||||||
|                 "path": "{Description}", |                 }, | ||||||
|                 "type": "text", |                 { | ||||||
|                 "column_name": "Description" |                     "path": "{Description}", | ||||||
|             }, |                     "type": "text", | ||||||
|             { |                     "column_name": "Description" | ||||||
|                 "path": "{Amount}", |                 }, | ||||||
|                 "type": "numeric", |                 { | ||||||
|                 "column_name": "Amount" |                     "path": "{Amount}", | ||||||
|             }, |                     "type": "numeric", | ||||||
|             { |                     "column_name": "Amount" | ||||||
|                 "path": "{Category}", |                 }, | ||||||
|                 "type": "text", |                 { | ||||||
|                 "column_name": "Category" |                     "path": "{Category}", | ||||||
|             } |                     "type": "text", | ||||||
|         ], |                     "column_name": "Category" | ||||||
|         "mapped": [ |                 } | ||||||
|             { |             ] | ||||||
|                 "path": "{Trans. Date}", |         }, | ||||||
|                 "type": "date", |         { | ||||||
|                 "column_name": "Trans. Date" |             "name": "mapped", | ||||||
|             }, |             "columns": [ | ||||||
|             { |                 { | ||||||
|                 "path": "{Post Date}", |                     "path": "{Trans. Date}", | ||||||
|                 "type": "date", |                     "type": "date", | ||||||
|                 "column_name": "Post Date" |                     "column_name": "Trans. Date" | ||||||
|             }, |                 }, | ||||||
|             { |                 { | ||||||
|                 "path": "{Description}", |                     "path": "{Post Date}", | ||||||
|                 "type": "text", |                     "type": "date", | ||||||
|                 "column_name": "Description" |                     "column_name": "Post Date" | ||||||
|             }, |                 }, | ||||||
|             { |                 { | ||||||
|                 "path": "{Amount}", |                     "path": "{Description}", | ||||||
|                 "type": "numeric", |                     "type": "text", | ||||||
|                 "column_name": "Amount" |                     "column_name": "Description" | ||||||
|             }, |                 }, | ||||||
|             { |                 { | ||||||
|                 "path": "{Category}", |                     "path": "{Amount}", | ||||||
|                 "type": "text", |                     "type": "numeric", | ||||||
|                 "column_name": "Category" |                     "column_name": "Amount" | ||||||
|             }, |                 }, | ||||||
|             { |                 { | ||||||
|                 "path": "{party}", |                     "path": "{Category}", | ||||||
|                 "type": "text", |                     "type": "text", | ||||||
|                 "column_name": "Party" |                     "column_name": "Category" | ||||||
|             }, |                 }, | ||||||
|             { |                 { | ||||||
|                 "path": "{reason}", |                     "path": "{party}", | ||||||
|                 "type": "text", |                     "type": "text", | ||||||
|                 "column_name": "Reason" |                     "column_name": "Party" | ||||||
|             } |                 }, | ||||||
|         ] |                 { | ||||||
|     } |                     "path": "{reason}", | ||||||
|  |                     "type": "text", | ||||||
|  |                     "column_name": "Reason" | ||||||
|  |                 } | ||||||
|  |             ] | ||||||
|  |         } | ||||||
|  |     ] | ||||||
| } | } | ||||||
							
								
								
									
										30
									
								
								database/upgrade_scripts/001.extract_schemas.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								database/upgrade_scripts/001.extract_schemas.sql
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | |||||||
|  | WITH | ||||||
|  | mod AS ( | ||||||
|  | SELECT  | ||||||
|  |     srce | ||||||
|  |     ,jsonb_pretty(defn) orig | ||||||
|  |     ,(defn - 'schemas')|| | ||||||
|  |     --rebuild the schemas key value from below | ||||||
|  |     jsonb_build_object( | ||||||
|  |         'schemas' | ||||||
|  |         --aggregate all the new key values for a single soure | ||||||
|  |         ,jsonb_agg( | ||||||
|  |             --combine a new key 'name' with the columns for that name | ||||||
|  |             jsonb_build_object('name',k)||jsonb_build_object('columns',v) | ||||||
|  |         ) | ||||||
|  |     ) rebuild | ||||||
|  | FROM  | ||||||
|  |     tps.srce | ||||||
|  |     LEFT JOIN LATERAL jsonb_each(defn->'schemas') WITH ORDINALITY je(k,v, rn) ON TRUE | ||||||
|  | GROUP BY | ||||||
|  |     srce | ||||||
|  |     ,defn | ||||||
|  | ) | ||||||
|  | UPDATE | ||||||
|  |     tps.srce s | ||||||
|  | SET | ||||||
|  |     defn = rebuild | ||||||
|  | FROM | ||||||
|  |     mod | ||||||
|  | WHERE | ||||||
|  |     mod.srce = s.srce | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user