Skip to content
sametcn99 edited this page Jan 22, 2025 · 3 revisions

Running Scripts in Linux

  • Navigate to the scripts directory.
  • Add execute permissions to the script using: chmod +x script_name.sh.
  • Run the script using: ./script_name.sh.

How to Run a Task in VS Code

  1. Open the Command Palette by pressing Ctrl+Shift+P.
  2. Type Run Task and select it from the dropdown menu.
  3. Choose your task from the list of available tasks.

How to Use Run and Debug Configurations in VS Code

  1. Open the Run and Debug Panel by pressing Ctrl+Shift+D.
  2. Select a configuration from the dropdown.
  3. Press the green play button (or F5) to start running the application.

How to Install Bun

Bun is an all-in-one JavaScript runtime & toolkit designed for speed, complete with a bundler, test runner, and Node.js-compatible package manager. Install it globally using:

npm install -g bun

Truncate All Tables in Public Schema

This script is written in PL/pgSQL and allows you to truncate all tables in the public schema of a PostgreSQL database. It removes all data from the tables, including those with foreign key dependencies, using the CASCADE option. This is particularly useful for resetting test or development environments.

Usage

To execute the script, simply run it in your PostgreSQL client or management tool (e.g., psql).

DO $$
DECLARE
    table_name TEXT;
BEGIN
    FOR table_name IN
        SELECT tablename
        FROM pg_tables
        WHERE schemaname = 'public'
    LOOP
        EXECUTE 'TRUNCATE TABLE ' || quote_ident(table_name) || ' CASCADE';
    END LOOP;
END
$$;

⚠️ Warning

  • This script permanently deletes all data in the public schema tables. Make sure to back up your data if necessary.
  • Only use this in non-production environments unless you are certain about the consequences.