0% found this document useful (0 votes)
102 views17 pages

Temp 2091396239

Uploaded by

matejviezan14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views17 pages

Temp 2091396239

Uploaded by

matejviezan14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 17

Welcome to Termux!

Docs: https://termux.dev/docs
Donate: https://termux.dev/donate
Community: https://termux.dev/community

Working with packages:

- Search: pkg search <query>


- Install: pkg install <package>
- Upgrade: pkg upgrade

Subscribing to additional repositories:

- Root: pkg install root-repo


- X11: pkg install x11-repo

For fixing any repository issues,


try 'termux-change-repo' command.

Report issues at https://termux.dev/issues


➜ ~ which nano
/data/data/com.termux/files/usr/bin/nano
➜ ~ mv /data/data/com.termux/files/usr/bin/nano{,.bak}
➜ ~ ln -s /data/data/com.termux/files/usr/bin/nano $(whi
ch vim)
ln: failed to create symbolic link '/data/data/com.termux
/files/usr/bin/vim': File exists
➜ ~ ln -s $(which vim) /data/data/com.termux/files/usr/b
in/nano
➜ ~ nano $PREFIX/var/lib/postgresql/postgresql.conf
➜ ~ pg_ctl -D $PREFIX/var/lib/postgresql start
waiting for server to start....2024-10-25 19:43:58.054 PS
T [24480] LOG: starting PostgreSQL 17.0 on aarch64-unkno
wn-linux-android, compiled by Android (12285214, +pgo, +b
olt, +lto, +mlgo, based on r522817b) clang version 18.0.2
(https://android.googlesource.com/toolchain/llvm-project
d8003a456d14a3deb8054cdaa529ffbf02d9b262), 64-bit
2024-10-25 19:43:58.056 PST [24480] LOG: listening on IP
v4 address "127.0.0.1", port 5432
2024-10-25 19:43:58.057 PST [24480] LOG: listening on Un
ix socket "/data/data/com.termux/files/usr/tmp/.s.PGSQL.5
432"
2024-10-25 19:43:58.066 PST [24485] LOG: database system
was shut down at 2024-10-25 19:22:12 PST
2024-10-25 19:43:58.075 PST [24480] LOG: database system
is ready to accept connections
done
server started
➜ ~ psql -U postgres -c "SHOW config_file;"
2024-10-25 19:46:07.630 PST [26114] FATAL: role "postgre
s" does not exist
psql: error: connection to server on socket "/data/data/c
om.termux/files/usr/tmp/.s.PGSQL.5432" failed: FATAL: ro
le "postgres" does not exist
➜ ~ 2024-10-25 19:48:58.166 PST [24483] LOG: checkpoint
starting: time
2024-10-25 19:49:02.551 PST [24483] LOG: checkpoint comp
lete: wrote 46 buffers (0.3%); 0 WAL file(s) added, 0 rem
oved, 0 recycled; write=4.345 s, sync=0.016 s, total=4.38
6 s; sync files=11, longest=0.007 s, average=0.002 s; dis
tance=269 kB, estimate=269 kB; lsn=0/152D890, redo lsn=0/
152D838
➜ ~ psql -U postgres -c "SHOW config_file;"
2024-10-25 19:52:19.167 PST [29473] FATAL: role "postgre
s" does not exist
psql: error: connection to server on socket "/data/data/c
om.termux/files/usr/tmp/.s.PGSQL.5432" failed: FATAL: ro
le "postgres" does not exist
➜ ~ psql
2024-10-25 19:54:31.336 PST [32103] FATAL: database "u0_
a337" does not exist
psql: error: connection to server on socket "/data/data/c
om.termux/files/usr/tmp/.s.PGSQL.5432" failed: FATAL: da
tabase "u0_a337" does not exist
➜ ~ pg_ctl -D $PREFIX/var/lib/postgresql start
pg_ctl: another server might be running; trying to start
server anyway
waiting for server to start....2024-10-25 19:54:41.761 PS
T [32283] FATAL: lock file "postmaster.pid" already exis
ts
2024-10-25 19:54:41.761 PST [32283] HINT: Is another pos
tmaster (PID 24480) running in data directory "/data/data
/com.termux/files/usr/var/lib/postgresql"?
stopped waiting
pg_ctl: could not start server
Examine the log output.
➜ ~ psql
2024-10-25 19:54:57.066 PST [32442] FATAL: database "u0_
a337" does not exist
psql: error: connection to server on socket "/data/data/c
om.termux/files/usr/tmp/.s.PGSQL.5432" failed: FATAL: da
tabase "u0_a337" does not exist
➜ ~ psql -U postgres
2024-10-25 19:56:43.732 PST [2818] FATAL: role "postgres
" does not exist
psql: error: connection to server on socket "/data/data/c
om.termux/files/usr/tmp/.s.PGSQL.5432" failed: FATAL: ro
le "postgres" does not exist
➜ ~ pg_ctl -D $PREFIX/var/lib/postgresql start
pg_ctl: another server might be running; trying to start
server anyway
waiting for server to start....2024-10-25 19:57:27.366 PS
T [3861] FATAL: lock file "postmaster.pid" already exist
s
2024-10-25 19:57:27.366 PST [3861] HINT: Is another post
master (PID 24480) running in data directory "/data/data/
com.termux/files/usr/var/lib/postgresql"?
stopped waiting
pg_ctl: could not start server
Examine the log output.
➜ ~ psql -d postgres
psql (17.0)
Type "help" for help.

postgres=# CREATE ROLE postgres';


postgres'# ALTER ROLE postgres SUPERUSER;
postgres'# \du
postgres'# CREATE ROLE postgres WITH LOGIN PASSWORD 'your
password';
postgres'# ALTER ROLE postgres SUPERUSER;
postgres'# psql -U postgres -c "SHOW config_file;"
postgres'# 2024-10-25 19:52:19.167 PST [29473] FATAL: ro
le "postgres" does not exist
postgres'# psql: error: connection to server on socket "/
data/data/com.termux/files/usr/tmp/.s.PGSQL.5432" failed:
FATAL: role "postgres" does not exist
postgres'#
postgres'# \du
postgres'#
postgres'# '
postgres-#
postgres-#
postgres-# \du
postgres-# CREATE ROLE postgres;
2024-10-25 20:18:47.615 PST [7798] ERROR: syntax error a
t or near "';
ALTER ROLE postgres SUPERUSER;
\du
CREATE ROLE postgres WITH LOGIN PASSWORD '" at ch
aracter 21
2024-10-25 20:18:47.615 PST [7798] STATEMENT: CREATE ROL
E postgres';
ALTER ROLE postgres SUPERUSER;
\du
CREATE ROLE postgres WITH LOGIN PASSWORD 'yourpas
sword';
ALTER ROLE postgres SUPERUSER;
psql -U postgres -c "SHOW config_file;"
2024-10-25 19:52:19.167 PST [29473] FATAL: role
"postgres" does not exist
psql: error: connection to server on socket "/dat
a/data/com.termux/files/usr/tmp/.s.PGSQL.5432" failed: FA
TAL: role "postgres" does not exist

\du

'
CREATE ROLE postgres;
ERROR: syntax error at or near "';
ALTER ROLE postgres SUPERUSER;
\du
CREATE ROLE postgres WITH LOGIN PASSWORD '"
LINE 1: CREATE ROLE postgres';
^
postgres=# CREATE ROLE postgres;
CREATE ROLE
postgres=# 2024-10-25 20:19:15.494 PST [24483] LOG: chec
kpoint starting: time
2024-10-25 20:19:15.925 PST [24483] LOG: checkpoint comp
lete: wrote 5 buffers (0.0%); 0 WAL file(s) added, 0 remo
ved, 0 recycled; write=0.404 s, sync=0.009 s, total=0.432
s; sync files=5, longest=0.006 s, average=0.002 s; dista
nce=3 kB, estimate=243 kB; lsn=0/152E6A8, redo lsn=0/152E
650
postgres=# ALTER ROLE postgres SUPERUSER;
ALTER ROLE
postgres=#
postgres=# \du
postgres=# ALTER ROLE postgres WITH LOGIN PASSWORD 'yourp
assword';
ALTER ROLE
postgres=# \du
postgres=# psql -U postgres -d postgres
postgres-# ^C
postgres=#
\q
➜ ~ psql -U postgres -d postgres
psql (17.0)
Type "help" for help.

postgres=# 2024-10-25 20:24:15.986 PST [24483] LOG: chec


kpoint starting: time
2024-10-25 20:24:16.121 PST [24483] LOG: checkpoint comp
lete: wrote 2 buffers (0.0%); 0 WAL file(s) added, 0 remo
ved, 0 recycled; write=0.102 s, sync=0.009 s, total=0.136
s; sync files=2, longest=0.007 s, average=0.005 s; dista
nce=2 kB, estimate=219 kB; lsn=0/152F200, redo lsn=0/152F
1A8
postgres=# CREATE TABLE users (
user_id SERIAL PRIMARY KEY,
username VARCHAR(100) UNIQUE NOT NULL, -- e.g., phone
number or unique identifier
display_name VARCHAR(100),
profile_picture_url TEXT,
status_message TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE
postgres=# CREATE TABLE chats (
postgres(# chat_id SERIAL PRIMARY KEY,
postgres(# chat_name VARCHAR(100), -- For group chats
postgres(# is_group BOOLEAN DEFAULT FALSE,
postgres(# created_at TIMESTAMP DEFAULT CURRENT_TIMES
TAMP
postgres(# );
CREATE TABLE
postgres=# CREATE TABLE participants (
postgres(# chat_id INT REFERENCES chats(chat_id) ON D
ELETE CASCADE,
postgres(# user_id INT REFERENCES users(user_id) ON D
ELETE CASCADE,
postgres(# is_admin BOOLEAN DEFAULT FALSE,
postgres(# joined_at TIMESTAMP DEFAULT CURRENT_TIMEST
AMP,
postgres(# PRIMARY KEY (chat_id, user_id)
postgres(# );
CREATE TABLE
postgres=# CREATE TABLE messages (
postgres(# message_id SERIAL PRIMARY KEY,
postgres(# chat_id INT REFERENCES chats(chat_id) ON D
ELETE CASCADE,
postgres(# sender_id INT REFERENCES users(user_id),
postgres(# content TEXT,
postgres(# media_id INT REFERENCES media(media_id),
postgres(# message_type VARCHAR(20) DEFAULT 'text', -
- 'text', 'image', 'video', etc.
postgres(# sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAM
P
postgres(# );
2024-10-25 20:44:01.745 PST [21501] ERROR: relation "med
ia" does not exist
2024-10-25 20:44:01.745 PST [21501] STATEMENT: CREATE TA
BLE messages (
message_id SERIAL PRIMARY KEY,
chat_id INT REFERENCES chats(chat_id) ON DELE
TE CASCADE,
sender_id INT REFERENCES users(user_id),
content TEXT,
media_id INT REFERENCES media(media_id),
message_type VARCHAR(20) DEFAULT 'text', -- '
text', 'image', 'video', etc.
sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
ERROR: relation "media" does not exist
postgres=# CREATE TABLE messages (
postgres(# message_id SERIAL PRIMARY KEY,
postgres(# chat_id INT REFERENCES chats(chat_id) ON D
ELETE CASCADE,
postgres(# sender_id INT REFERENCES users(user_id),
postgres(# content TEXT,
postgres(# media_id INT REFERENCES media(media_id),
postgres(# message_type VARCHAR(20) DEFAULT 'text', -
- 'text', 'image', 'video', etc.
postgres(# sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAM
P
postgres(# );
2024-10-25 20:44:13.504 PST [21501] ERROR: relation "med
ia" does not exist
2024-10-25 20:44:13.504 PST [21501] STATEMENT: CREATE TA
BLE messages (
message_id SERIAL PRIMARY KEY,
chat_id INT REFERENCES chats(chat_id) ON DELE
TE CASCADE,
sender_id INT REFERENCES users(user_id),
content TEXT,
media_id INT REFERENCES media(media_id),
message_type VARCHAR(20) DEFAULT 'text', -- '
text', 'image', 'video', etc.
sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
ERROR: relation "media" does not exist
postgres=# 2024-10-25 20:44:15.422 PST [24483] LOG: chec
kpoint starting: time
postgres=# 2024-10-25 20:44:23.410 PST [24483] LOG: chec
kpoint complete: wrote 80 buffers (0.5%); 0 WAL file(s) a
dded, 0 removed, 0 recycled; write=7.948 s, sync=0.020 s,
total=7.989 s; sync files=65, longest=0.006 s, average=0
.001 s; distance=296 kB, estimate=296 kB; lsn=0/1579208,
redo lsn=0/15791B0
CREATE TABLE participants (
postgres(# chat_id INT REFERENCES chats(chat_id) ON D
ELETE CASCADE,
postgres(# user_id INT REFERENCES users(user_id) ON D
ELETE CASCADE,
postgres(# is_admin BOOLEAN DEFAULT FALSE,
postgres(# joined_at TIMESTAMP DEFAULT CURRENT_TIMEST
AMP,
postgres(# PRIMARY KEY (chat_id, user_id)
postgres(# );
2024-10-25 20:44:24.343 PST [21501] ERROR: relation "par
ticipants" already exists
2024-10-25 20:44:24.343 PST [21501] STATEMENT: CREATE TA
BLE participants (
chat_id INT REFERENCES chats(chat_id) ON DELE
TE CASCADE,
user_id INT REFERENCES users(user_id) ON DELE
TE CASCADE,
is_admin BOOLEAN DEFAULT FALSE,
joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
,
PRIMARY KEY (chat_id, user_id)
);
ERROR: relation "participants" already exists
postgres=# CREATE TABLE media (
postgres(# media_id SERIAL PRIMARY KEY,
postgres(# media_url TEXT NOT NULL,
postgres(# media_type VARCHAR(20), -- 'image', 'video
', 'audio', 'document'
postgres(# thumbnail_url TEXT, -- For videos or image
s
postgres(# uploaded_at TIMESTAMP DEFAULT CURRENT_TIME
STAMP
postgres(# );
CREATE TABLE
postgres=# CREATE TABLE messages (
postgres(# message_id SERIAL PRIMARY KEY,
postgres(# chat_id INT REFERENCES chats(chat_id) ON D
ELETE CASCADE,
postgres(# sender_id INT REFERENCES users(user_id),
postgres(# content TEXT,
postgres(# media_id INT REFERENCES media(media_id),
postgres(# message_type VARCHAR(20) DEFAULT 'text', -
- 'text', 'image', 'video', etc.
postgres(# sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAM
P
postgres(# );
CREATE TABLE
postgres=# CREATE TABLE message_statuses (
postgres(# message_id INT REFERENCES messages(message
_id) ON DELETE CASCADE,
postgres(# user_id INT REFERENCES users(user_id),
postgres(# status VARCHAR(20) DEFAULT 'sent', -- 'sen
t', 'delivered', 'read'
postgres(# updated_at TIMESTAMP DEFAULT CURRENT_TIMES
TAMP,
postgres(# PRIMARY KEY (message_id, user_id)
postgres(# );
CREATE TABLE
postgres=# CREATE TABLE encryption_keys (
postgres(# user_id INT REFERENCES users(user_id) ON D
ELETE CASCADE,
postgres(# device_id VARCHAR(100),
postgres(# public_key TEXT NOT NULL,
postgres(# created_at TIMESTAMP DEFAULT CURRENT_TIMES
TAMP,
postgres(# PRIMARY KEY (user_id, device_id)
postgres(# );
CREATE TABLE
postgres=# \dt *.*
postgres=# SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_type = 'BASE TABLE'
ORDER BY table_schema, table_name;
postgres=# \d users;
\d chats;
\d participants;
\d messages;
\d media;
\d message_statuses;
postgres=# SELECT current_database();
current_database
------------------
postgres
(1 row)

postgres=# o
postgres-# ^C
postgres=#
\q
➜ ~
➜ ~ pg_dump -U postgres -d postgres --schema-only --tabl
e=users --table=chats --table=participants --table=messag
es --table=media --table=message_statuses > schema_dump.s
ql
➜ ~ postgres
postgres does not know where to find the server configura
tion file.
You must specify the --config-file or -D invocation optio
n or set the PGDATA environment variable.
➜ ~ ls
alpine
android-sdk
bin
data.json
downloads
final_install_recording.sh
llama.cpp
mysession.log
openai_rest_service.go
openai_rest_service_with_config.go
openai_service_archive.tar.gz
schema_dump.sql
start-ubuntu.sh
storage
t-20241020061925.apkg
terminal_recording_script.sh
terminal_sessions
typescript
ubuntu-binds
ubuntu-fs
ubuntu.sh
update_replay_session.patch
➜ ~ bin/share_file.sh schema_dump.sql
Starting: Intent { act=android.intent.action.CREATE_DOCUM
ENT typ=text/plain cmp=com.google.android.documentsui/com
.android.documentsui.picker.PickActivity (has extras) }
➜ ~ less !!:1
➜ ~ less schema_dump.sql
➜ ~ cp ~/downloads/openai_rest_service_patch.patch .c
➜ ~
➜ ~
➜ ~
➜ ~
➜ ~ vi bin/share_file.sh
➜ ~ bin/share_file.sh schema_dump.sql
Starting: Intent { act=android.intent.action.CREATE_DOCUM
ENT typ=text/plain cmp=com.google.android.documentsui/com
.android.documentsui.picker.PickActivity (has extras) }
➜ ~ vi bin/share_file.sh
➜ ~ # I-set ang file path gikan sa positional argument
FILE_PATH="file://$1"

# Kuhaa ang title gikan sa file path


FILE_TITLE=$(basename "$FILE_PATH")

# I-execute ang termux-am command


am start -n com.google.android.documentsui/com.andro
id.documentsui.picker.PickActivity -a android.intent.acti
on.CREATE_DOCUMENT -t text/plain --es android.intent.extr
a.STREAM schema_dump.sql --es android.provider.extra.SHOW
_ADVANCED "1"
➜ ~ am start -n com.google.android.docu
mentsui/com.android.documentsui.picker.PickActivity -a an
droid.intent.action.CREATE_DOCUMENT -t text/plain --es an
droid.intent.extra.STREAM schema_dump.sql --es android.pr
ovider.extra.SHOW_ADVANCED "1"
Starting: Intent { act=android.intent.action.CREATE_DOCUM
ENT typ=text/plain cmp=com.google.android.documentsui/com
.android.documentsui.picker.PickActivity (has extras) }
➜ ~ am start -n com.google.android.docu
mentsui/com.android.documentsui.picker.PickActivity -a an
droid.intent.action.CREATE_DOCUMENT --es android.intent.e
xtra.STREAM schema_dump.sql --es android.provider.extra.S
HOW_ADVANCED "1"
Starting: Intent { act=android.intent.action.CREATE_DOCUM
ENT cmp=com.google.android.documentsui/com.android.docume
ntsui.picker.PickActivity (has extras) }
➜ ~ am start -n com.google.android.docu
mentsui/com.android.documentsui.picker.PickActivity -a an
droid.intent.action.CREATE_DOCUMENT --es android.intent.e
xtra.STREAM schema_dump.sql
Starting: Intent { act=android.intent.action.CREATE_DOCUM
ENT cmp=com.google.android.documentsui/com.android.docume
ntsui.picker.PickActivity (has extras) }
➜ ~ am start -n com.google.android.docu
mentsui/com.android.documentsui.picker.PickActivity -a an
droid.intent.action.CREATE_DOCUMENT schema_dump.sql
Starting: Intent { act=android.intent.action.CREATE_DOCUM
ENT pkg=schema_dump.sql cmp=com.google.android.documentsu
i/com.android.documentsui.picker.PickActivity }
Warning: Activity not started, its current task has been
brought to the front
➜ ~ am start -n com.google.android.docu
mentsui/com.android.documentsui.picker.PickActivity -a an
droid.intent
Starting: Intent { act=android.intent cmp=com.google.andr
oid.documentsui/com.android.documentsui.picker.PickActivi
ty }
➜ ~ # I-set ang file path gikan sa positional argument
FILE_PATH="file://$1"

# Kuhaa ang title gikan sa file path


FILE_TITLE=$(basename "$FILE_PATH")

# I-execute ang termux-am command


am start -n com.google.android.documentsui/com.andro
id.documentsui.picker.PickActivity -a android.intent.acti
on.CREATE_DOCUMENT -t text/plain --es android.intent.extr
a.STREAM schema_dump.sql --es android.provider.extra.SHOW
_ADVANCED "1"
➜ ~ # I-set ang file path gikan sa positional argument
FILE_PATH="file://$1"

# Kuhaa ang title gikan sa file path


FILE_TITLE=$(basename "$FILE_PATH")

# I-execute ang termux-am command


am start -n com.google.android.documentsui/com.andro
id.documentsui.picker.PickActivity -a android.intent.acti
on.CREATE_DOCUMENT -t text/plain --es android.intent.extr
a.STREAM schema_dump.sql --es android.provider.extra.SHOW
_ADVANCED "1"⌀⌀ĭəœĭĭžľffffij
➜ ~
➜ ~ # I-set ang file path gikan sa positional argument
FILE_PATH="file://$1"

# Kuhaa ang title gikan sa file path


FILE_TITLE=$(basename "$FILE_PATH")

# I-execute ang termux-am command


am start -n com.google.android.documentsui/com.andro
id.documentsui.picker.PickActivity -a android.intent.acti
on.CREATE_DOCUMENT -t text/plain --es android.intent.extr
a.STREAM schema_dump.sql --es android.provider.extra.SHOW
_ADVANCED "1"
➜ ~ # I-set ang file path gikan sa positional argument
FILE_PATH="file://$1"

# Kuhaa ang title gikan sa file path


FILE_TITLE=$(basename "$FILE_PATH")

# I-execute ang termux-am command


am start -n com.google.android.documentsui/com.andro
id.documentsui.picker.PickActivity -a android.intent.acti
on.CREATE_DOCUMENT -t text/plain --es android.intent.extr
a.STREAM schema_dump.sql --es android.provider.extra.SHOW
_ADVANCED "1"
➜ ~ # I-set ang file path gikan sa positional argument
FILE_PATH="file://$1"
# Kuhaa ang title gikan sa file path
FILE_TITLE=$(basename "$FILE_PATH")

# I-execute ang termux-am command


am start -n com.google.android.documentsui/com.andro
id.documentsui.picker.PickActivity -a android.intent.acti
on.CREATE_DOCUMENT -t text/plain --es android.intent.extr
a.STREAM schema_dump.sql --es android.provider.extra.SHOW
_ADVANCED "1"
➜ ~ # I-set ang file path gikan sa positional argument
FILE_PATH="file://$1"

# Kuhaa ang title gikan sa file path


FILE_TITLE=$(basename "$FILE_PATH")

# I-execute ang termux-am command


am start -n com.google.android.documentsui/com.andro
id.documentsui.picker.PickActivity -a android.intent.acti
on.CREATE_DOCUMENT -t text/plain --es android.intent.extr
a.STREAM schema_dump.sql --es android.provider.extra.SHOW
_ADVANCED "1"
➜ ~
➜ ~
➜ ~
➜ ~
➜ ~ pg_dump -U postgres -d postgres --schema-only --tabl
e=users --table=chats --table=participants --table=messag
es --table=media --table=message_statuses
--
-- PostgreSQL database dump
--

-- Dumped from database version 17.0


-- Dumped by pg_dump version 17.0

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET transaction_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: chats; Type: TABLE; Schema: public; Owner: postg
res
--

CREATE TABLE public.chats (


chat_id integer NOT NULL,
chat_name character varying(100),
is_group boolean DEFAULT false,
created_at timestamp without time zone DEFAULT CURREN
T_TIMESTAMP
);

ALTER TABLE public.chats OWNER TO postgres;

--
-- Name: chats_chat_id_seq; Type: SEQUENCE; Schema: publi
c; Owner: postgres
--

CREATE SEQUENCE public.chats_chat_id_seq


AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

ALTER SEQUENCE public.chats_chat_id_seq OWNER TO postgres


;

--
-- Name: chats_chat_id_seq; Type: SEQUENCE OWNED BY; Sche
ma: public; Owner: postgres
--

ALTER SEQUENCE public.chats_chat_id_seq OWNED BY public.c


hats.chat_id;

--
-- Name: media; Type: TABLE; Schema: public; Owner: postg
res
--

CREATE TABLE public.media (


media_id integer NOT NULL,
media_url text NOT NULL,
media_type character varying(20),
thumbnail_url text,
uploaded_at timestamp without time zone DEFAULT CURRE
NT_TIMESTAMP
);

ALTER TABLE public.media OWNER TO postgres;

--
-- Name: media_media_id_seq; Type: SEQUENCE; Schema: publ
ic; Owner: postgres
--

CREATE SEQUENCE public.media_media_id_seq


AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

ALTER SEQUENCE public.media_media_id_seq OWNER TO postgre


s;

--
-- Name: media_media_id_seq; Type: SEQUENCE OWNED BY; Sch
ema: public; Owner: postgres
--

ALTER SEQUENCE public.media_media_id_seq OWNED BY public.


media.media_id;

--
-- Name: message_statuses; Type: TABLE; Schema: public; O
wner: postgres
--

CREATE TABLE public.message_statuses (


message_id integer NOT NULL,
user_id integer NOT NULL,
status character varying(20) DEFAULT 'sent'::characte
r varying,
updated_at timestamp without time zone DEFAULT CURREN
T_TIMESTAMP
);

ALTER TABLE public.message_statuses OWNER TO postgres;

--
-- Name: messages; Type: TABLE; Schema: public; Owner: po
stgres
--

CREATE TABLE public.messages (


message_id integer NOT NULL,
chat_id integer,
sender_id integer,
content text,
media_id integer,
message_type character varying(20) DEFAULT 'text'::ch
aracter varying,
sent_at timestamp without time zone DEFAULT CURRENT_T
IMESTAMP
);

ALTER TABLE public.messages OWNER TO postgres;

--
-- Name: messages_message_id_seq; Type: SEQUENCE; Schema:
public; Owner: postgres
--
CREATE SEQUENCE public.messages_message_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

ALTER SEQUENCE public.messages_message_id_seq OWNER TO po


stgres;

--
-- Name: messages_message_id_seq; Type: SEQUENCE OWNED BY
; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.messages_message_id_seq OWNED BY pu


blic.messages.message_id;

--
-- Name: participants; Type: TABLE; Schema: public; Owner
: postgres
--

CREATE TABLE public.participants (


chat_id integer NOT NULL,
user_id integer NOT NULL,
is_admin boolean DEFAULT false,
joined_at timestamp without time zone DEFAULT CURRENT
_TIMESTAMP
);

ALTER TABLE public.participants OWNER TO postgres;

--
-- Name: users; Type: TABLE; Schema: public; Owner: postg
res
--

CREATE TABLE public.users (


user_id integer NOT NULL,
username character varying(100) NOT NULL,
display_name character varying(100),
profile_picture_url text,
status_message text,
created_at timestamp without time zone DEFAULT CURREN
T_TIMESTAMP
);

ALTER TABLE public.users OWNER TO postgres;

--
-- Name: users_user_id_seq; Type: SEQUENCE; Schema: publi
c; Owner: postgres
--

CREATE SEQUENCE public.users_user_id_seq


AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

ALTER SEQUENCE public.users_user_id_seq OWNER TO postgres


;

--
-- Name: users_user_id_seq; Type: SEQUENCE OWNED BY; Sche
ma: public; Owner: postgres
--

ALTER SEQUENCE public.users_user_id_seq OWNED BY public.u


sers.user_id;

--
-- Name: chats chat_id; Type: DEFAULT; Schema: public; Ow
ner: postgres
--

ALTER TABLE ONLY public.chats ALTER COLUMN chat_id SET DE


FAULT nextval('public.chats_chat_id_seq'::regclass);

--
-- Name: media media_id; Type: DEFAULT; Schema: public; O
wner: postgres
--

ALTER TABLE ONLY public.media ALTER COLUMN media_id SET D


EFAULT nextval('public.media_media_id_seq'::regclass);

--
-- Name: messages message_id; Type: DEFAULT; Schema: publ
ic; Owner: postgres
--

ALTER TABLE ONLY public.messages ALTER COLUMN message_id


SET DEFAULT nextval('public.messages_message_id_seq'::reg
class);

--
-- Name: users user_id; Type: DEFAULT; Schema: public; Ow
ner: postgres
--

ALTER TABLE ONLY public.users ALTER COLUMN user_id SET DE


FAULT nextval('public.users_user_id_seq'::regclass);
--
-- Name: chats chats_pkey; Type: CONSTRAINT; Schema: publ
ic; Owner: postgres
--

ALTER TABLE ONLY public.chats


ADD CONSTRAINT chats_pkey PRIMARY KEY (chat_id);

--
-- Name: media media_pkey; Type: CONSTRAINT; Schema: publ
ic; Owner: postgres
--

ALTER TABLE ONLY public.media


ADD CONSTRAINT media_pkey PRIMARY KEY (media_id);

--
-- Name: message_statuses message_statuses_pkey; Type: CO
NSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.message_statuses


ADD CONSTRAINT message_statuses_pkey PRIMARY KEY (mes
sage_id, user_id);

--
-- Name: messages messages_pkey; Type: CONSTRAINT; Schema
: public; Owner: postgres
--

ALTER TABLE ONLY public.messages


ADD CONSTRAINT messages_pkey PRIMARY KEY (message_id)
;

--
-- Name: participants participants_pkey; Type: CONSTRAINT
; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.participants


ADD CONSTRAINT participants_pkey PRIMARY KEY (chat_id
, user_id);

--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: publ
ic; Owner: postgres
--

ALTER TABLE ONLY public.users


ADD CONSTRAINT users_pkey PRIMARY KEY (user_id);

--
-- Name: users users_username_key; Type: CONSTRAINT; Sche
ma: public; Owner: postgres
--

ALTER TABLE ONLY public.users


ADD CONSTRAINT users_username_key UNIQUE (username);

--
-- Name: message_statuses message_statuses_message_id_fke
y; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.message_statuses


ADD CONSTRAINT message_statuses_message_id_fkey FOREI
GN KEY (message_id) REFERENCES public.messages(message_id
) ON DELETE CASCADE;

--
-- Name: message_statuses message_statuses_user_id_fkey;
Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.message_statuses


ADD CONSTRAINT message_statuses_user_id_fkey FOREIGN
KEY (user_id) REFERENCES public.users(user_id);

--
-- Name: messages messages_chat_id_fkey; Type: FK CONSTRA
INT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.messages


ADD CONSTRAINT messages_chat_id_fkey FOREIGN KEY (cha
t_id) REFERENCES public.chats(chat_id) ON DELETE CASCADE;

--
-- Name: messages messages_media_id_fkey; Type: FK CONSTR
AINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.messages


ADD CONSTRAINT messages_media_id_fkey FOREIGN KEY (me
dia_id) REFERENCES public.media(media_id);

--
-- Name: messages messages_sender_id_fkey; Type: FK CONST
RAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.messages


ADD CONSTRAINT messages_sender_id_fkey FOREIGN KEY (s
ender_id) REFERENCES public.users(user_id);
--
-- Name: participants participants_chat_id_fkey; Type: FK
CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.participants


ADD CONSTRAINT participants_chat_id_fkey FOREIGN KEY
(chat_id) REFERENCES public.chats(chat_id) ON DELETE CASC
ADE;

--
-- Name: participants participants_user_id_fkey; Type: FK
CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.participants


ADD CONSTRAINT participants_user_id_fkey FOREIGN KEY
(user_id) REFERENCES public.users(user_id) ON DELETE CASC
ADE;

--
-- PostgreSQL database dump complete
--

➜ ~

You might also like