Package: discord-to-postgresql
Discord to PostgreSQLImports Discord messages archive to PostgreSQL database.Tested in Python 3.7, 3.8, and 3.9 on Linux and Windows.Installationpip3 install discord-to-postgresqlUsageRun with postgresql credentials as argumentsdiscord_to_postgresql path/to/package.zip replace myusername mypassword 0.0.0.0 5432 postgresRun with textfile containing PostgreSQL connection URL specified as argumentdiscord_to_postgresql path/to/package.zip replace -t path/to/conn_url.txtSample contents of textfilepostgresql://myusername:mypassword@0.0.0.0:5432/postgresPostgreSQL output tablesdiscord_userColumnTypeidbigintusernamecharacter varyingdiscriminatorcharacter varyingdiscord_serverColumnTypeidbigintnamecharacter varyingdiscord_channeltypeis the "type" of the discord channel. Known possible values oftypeare:0 = normal server channel1 = direct message (between 2 people only)3 = group chat (may be more than 2 people)5 = announcement channel11 = threadColumnTypeidbiginttypeintegernamecharacter varyingserver_idbigintdiscord_recipientA private chat will have 2 "recipients" (members), or 1-8 for group chats.ColumnTypechannel_idbigintuser_idbigintdiscord_messageColumnTypeidbiginttimestamptimestamp without time zonecontentstextattachmentscharacter varyingchannel_idbigintuser_idbigintCommand-line arguments--package: package.zip file path.--if_exists: How to behave if the tables already exist. This argument will be directly passed to the DataFrame.to_sql() function.
Possible values:fail: Raise a ValueError.replace: Drop the table before inserting new values.append: Insert new values to the existing table.--username: PostgreSQL server username. Optional if text_file_with_url already specified.--password: PostgreSQL server password. Optional if text_file_with_url already specified.--host: PostgreSQL server host URL (e.g. localhost or xxx.xxx.xxx.xxx). Optional if text_file_with_url already specified.--port: PostgreSQL server port. Optional if text_file_with_url already specified.--db_name: PostgreSQL server database name. Optional if text_file_with_url already specified.--text_file_with_url: Text file containing PostgreSQL DB connection URL. Optional if username, password, host, port, db_name are all specified.
URL is of the format:postgresql://<USERNAME>:<PASSWORD>@<HOST>:<PORT>/<DB_NAME>Addendum: Easiest way to start up a test PostgreSQL serverInstall Docker:https://docs.docker.com/engine/install/Then type this command to install a Docker PostgreSQL image and run as a container:docker run -p 5432:5432 --name test-postgres -e POSTGRES_USER=myusername -e POSTGRES_PASSWORD=mypassword -e POSTGRES_DB=postgres -d postgresThis will run a postgresql server accessible onlocalhost:5432with usernamemyusernameand passwordmypassword, and create a databased namedpostgres.To stop the container:docker stop test-postgresTo restart the container:docker start test-postgresTo delete the container (and erase all db data):docker rm test-postgresafter which it is completely fine to run the above-mentioneddocker runcommand again.Heroku Postgres (free cloud server) is another option but has a maximum row number limit.TODOTest for other versions of PythonTest for WindowsAdd support for primary keys (no duplicate rows if append)