Showing posts with label PostgreeSQL. Show all posts
Showing posts with label PostgreeSQL. Show all posts

Tuesday, September 7, 2021

PSQL Command For Restoring SQL File in Postgresql

 


Thursday, May 6, 2021

Belajar Ngekonekin Django ke Postgresql

 Sipss.. pertama-tama silahkan buat project seperti pada postingan ini....

Setelah itu buat database baru di postgresql (atau db yg lama jg boleh ehe)


Sipsss.. setelah itu install psycopg2-binary (ini kyk driver buat postgresql)

pipenv install pyscopg2-binary


Abis install psycopg2-binary tar mncul gini di pipfilenya:

Siipss.. next kita tambahkan informasi db-nya ke file setting django seperti terlihat dibawah:



Naah.. sampe sini udah selese deeeh... buat ngecek g' ada yg error silahkan run servernya:
python manage.py runserver YOUR_PORT


Sipss.. sampai disini sebenernya udah okie.. temen2 udah bisa explore2 yg lain... cuman klu mau lebih bagus... informasi kayk nama db, user, password itu sebaiknya disimpen di .env jadi g' kliatan sama orang2 luar klu misalkan diupload sourcenya ke git atau tempat lain... naah buat ngehandle yg ini, kita install library baru, namanya django-environ... So silahkan diinstall...


Abis itu kita buat file baru .env yg lokasi filenya HARUS sama dengan lokasi settingan file django kyk gini:

Naah setelah itu kita bikin variabel2 di dalam .env-nya kyk gini ajjah:

Terus variabel2 dari .env-nya kita load di setting.py kyk gini:

Setelah itu kita ganti semua variabel2 db sebelumnya :

Naah.. kyk gitu lbih cantik keliatan hehehe.. dan rahasianya terjaga :D

Siipsss... daaah... semoga bermanfaat :-)

Thursday, September 19, 2019

Remove NOT NULL Constraint in Postgresql Using SQL Script

So I have a table called 'changes' with column name 'test' and it's constraint as 'NOT NULL'

To remove NOT NULL constraint, just execute this script in pgAdmin :


alter table changes alter column test drop not null;

Result :

Wednesday, September 18, 2019

Create a Very Simple Trigger in pgAdmin 4 - Postgresql

This post will gonna guide you to create a very simple simple trigger in pgAdmin 4.
First thing first is create a new trigger function inside a schema. Please follow the step frow below pictures

Then put the trigger function name :
Then put the code as shown below

So here we only add a RAISE NOTICE. This is actually like a logger, so everytime this function is executed there will be a notification message in our pgAdmin console. Later we'll gonna see the result. And for return NEW, we'll gonna explain it later in more detail in the next post. Well... That's alll,... Just hit the SAVE button aaand we'll gonna see our trigger functions in the list like this :

Next.....
Let's choose a table to trigger our trigger function. In this post I chose akatsuki_users. So inside of akatsuki_users just right click the Triggers menu and choose "Create --> Trigger" :
Then put a trigger name :
Choose trigger function from dropdown list :

Specify the trigger event :
The last step is hit SAVE button... and doneee.... yeeeei.....

Next... Let's try it.....
And because this trigger is fired when INSERT and UPDATE sooo let's try to insert something to akatsuki_users :
So we can see our notification message from our trigger function. But this is an INSERT. Let's try UPDATE :


Coool... So from INSERT and UPDATE we can see that our trigger function is successfully triggered...


Thursday, January 17, 2019

Konfigurasi Database cakePHP 2.10.13 menggunakan postgresql

1. buat file baru bernama database.php didalam directory config. Kemudian copy isi dari database.php.default kedalam database.php seperti terlihat pada contoh dibawah :

Jika kita buka localhost maka akan ditampilkan "Your database configuration is present" cuman connectionnya masih missing seperti terlihat dibawah :

2. Berikutnya kita bikin database baru di Pgadmin postgresql. Langkah2nya seperti terlihat dibawah:


3. Silahkan input database dari step 2 ke database.php seperti terlihat dibawah:

Hasilnya :


Seeepssss.... selese daaah....