├── .github ├── CODE_OF_CONDUCT.md ├── ISSUE_TEMPLATE.md ├── ISSUE_TEMPLATE │ └── bug_report.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── polls-database-schema ├── polls-schema.sql └── readme.md └── postgresql-adventureworks ├── AdventureWorksPG.gz ├── Call-CreatePGFlexServer.ps1 ├── CreatePostgreSQLFlexibleServer.ps1 ├── README.md └── media ├── 1a-RunFunction.JPG ├── 1b-ServerName.JPG ├── 1c-Extensions.JPG ├── 2a-PSQLLogin.JPG ├── 2b-CreateDatabase.JPG ├── 3a-RestoreDatabase.JPG ├── 4a-RegisterServer.JPG └── 4b-AWExpanded.JPG /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 4 | > Please provide us with the following information: 5 | > --------------------------------------------------------------- 6 | 7 | ### This issue is for a: (mark with an `x`) 8 | ``` 9 | - [ ] bug report -> please search issues before submitting 10 | - [ ] feature request 11 | - [ ] documentation issue or request 12 | - [ ] regression (a behavior that used to work and stopped in a new release) 13 | ``` 14 | 15 | ### Minimal steps to reproduce 16 | > 17 | 18 | ### Any log messages given by the failure 19 | > 20 | 21 | ### Expected/desired behavior 22 | > 23 | 24 | ### OS and Version? 25 | > Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?) 26 | 27 | ### Versions 28 | > 29 | 30 | ### Mention any other details that might be useful 31 | 32 | > --------------------------------------------------------------- 33 | > Thanks! We'll be in touch soon. 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Purpose 2 | 3 | * ... 4 | 5 | ## Does this introduce a breaking change? 6 | 7 | ``` 8 | [ ] Yes 9 | [ ] No 10 | ``` 11 | 12 | ## Pull Request Type 13 | What kind of change does this Pull Request introduce? 14 | 15 | 16 | ``` 17 | [ ] Bugfix 18 | [ ] Feature 19 | [ ] Code style update (formatting, local variables) 20 | [ ] Refactoring (no functional changes, no api changes) 21 | [ ] Documentation content changes 22 | [ ] Other... Please describe: 23 | ``` 24 | 25 | ## How to Test 26 | * Get the code 27 | 28 | ``` 29 | git clone [repo-address] 30 | cd [repo-name] 31 | git checkout [branch-name] 32 | npm install 33 | ``` 34 | 35 | * Test the code 36 | 37 | ``` 38 | ``` 39 | 40 | ## What to Check 41 | Verify that the following are valid 42 | * ... 43 | 44 | ## Other Information 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [project-title] Changelog 2 | 3 | 4 | # x.y.z (yyyy-mm-dd) 5 | 6 | *Features* 7 | * ... 8 | 9 | *Bug Fixes* 10 | * ... 11 | 12 | *Breaking Changes* 13 | * ... 14 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to [project-title] 2 | 3 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 4 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 5 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. 6 | 7 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide 8 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions 9 | provided by the bot. You will only need to do this once across all repos using our CLA. 10 | 11 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 12 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 13 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 14 | 15 | - [Code of Conduct](#coc) 16 | - [Issues and Bugs](#issue) 17 | - [Feature Requests](#feature) 18 | - [Submission Guidelines](#submit) 19 | 20 | ## Code of Conduct 21 | Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 22 | 23 | ## Found an Issue? 24 | If you find a bug in the source code or a mistake in the documentation, you can help us by 25 | [submitting an issue](#submit-issue) to the GitHub Repository. Even better, you can 26 | [submit a Pull Request](#submit-pr) with a fix. 27 | 28 | ## Want a Feature? 29 | You can *request* a new feature by [submitting an issue](#submit-issue) to the GitHub 30 | Repository. If you would like to *implement* a new feature, please submit an issue with 31 | a proposal for your work first, to be sure that we can use it. 32 | 33 | * **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr). 34 | 35 | ## Submission Guidelines 36 | 37 | ### Submitting an Issue 38 | Before you submit an issue, search the archive, maybe your question was already answered. 39 | 40 | If your issue appears to be a bug, and hasn't been reported, open a new issue. 41 | Help us to maximize the effort we can spend fixing issues and adding new 42 | features, by not reporting duplicate issues. Providing the following information will increase the 43 | chances of your issue being dealt with quickly: 44 | 45 | * **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps 46 | * **Version** - what version is affected (e.g. 0.1.2) 47 | * **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you 48 | * **Browsers and Operating System** - is this a problem with all browsers? 49 | * **Reproduce the Error** - provide a live example or a unambiguous set of steps 50 | * **Related Issues** - has a similar issue been reported before? 51 | * **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be 52 | causing the problem (line of code or commit) 53 | 54 | You can file new issues by providing the above information at the corresponding repository's issues link: https://github.com/[organization-name]/[repository-name]/issues/new]. 55 | 56 | ### Submitting a Pull Request (PR) 57 | Before you submit your Pull Request (PR) consider the following guidelines: 58 | 59 | * Search the repository (https://github.com/[organization-name]/[repository-name]/pulls) for an open or closed PR 60 | that relates to your submission. You don't want to duplicate effort. 61 | 62 | * Make your changes in a new git fork: 63 | 64 | * Commit your changes using a descriptive commit message 65 | * Push your fork to GitHub: 66 | * In GitHub, create a pull request 67 | * If we suggest changes then: 68 | * Make the required updates. 69 | * Rebase your fork and force push to your GitHub repository (this will update your Pull Request): 70 | 71 | ```shell 72 | git rebase master -i 73 | git push -f 74 | ``` 75 | 76 | That's it! Thank you for your contribution! 77 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sample Databases for Azure Database for PostgreSQL flexible server 2 | 3 | There are two sample database options for you to use: 4 | - [Adeventure works](./postgresql-adventureworks) : Use this sample to create a adventure works databases . 5 | - [Polls database schema](./polls-database-schema) : Use this sample to create a lightweight polls application. This sample has only the database schema. 6 | 7 | **You can use the runtime of your choice (Python, PHP, .NET , Node JS etc) to build using these samples.** Note that this repository only contains sample databases schema with some data. It does not contain any application code. 8 | 9 | ## Getting Started 10 | Follow the steps below to install these scripts out on your server. 11 | 12 | ### Prerequisites 13 | 14 | - You need an Azure subscription. Sign up for Free trial and you can get 12 months free with [Azure Database for PostgreSQL Flexilbe server](https://docs.microsoft.com/en-us/azure/postgresql/flexible-server/how-to-deploy-on-azure-free-account). 15 | - Install a client tool for Postgres - [psql](https://www.postgresql.org/docs/current/app-psql.html) , [pgadmin ](https://www.pgadmin.org/) 16 | 17 | ## Resources 18 | Azure Database for MySQL Flexible Server [Documentation](https://docs.microsoft.com/en-us/azure/mysql/flexible-server/) 19 | -------------------------------------------------------------------------------- /polls-database-schema/polls-schema.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE poll ; 2 | 3 | CREATE SEQUENCE users_seq; 4 | 5 | CREATE TABLE users ( 6 | id BIGINT NOT NULL DEFAULT NEXTVAL ('users_seq'), 7 | firstName VARCHAR(50) NULL DEFAULT NULL, 8 | lastName VARCHAR(50) NULL DEFAULT NULL, 9 | email VARCHAR(50) NULL, 10 | passwordHash VARCHAR(32) NOT NULL, 11 | host SMALLINT NOT NULL DEFAULT 0, 12 | registeredAt TIMESTAMP(0) NOT NULL, 13 | lastLogin TIMESTAMP(0) NULL DEFAULT NULL, 14 | intro TEXT NULL DEFAULT NULL, 15 | displayName TEXT NULL DEFAULT NULL, 16 | PRIMARY KEY (id)); 17 | 18 | CREATE SEQUENCE poll_seq; 19 | 20 | CREATE TABLE poll ( 21 | id BIGINT NOT NULL DEFAULT NEXTVAL ('poll_seq'), 22 | surveyHostId BIGINT NOT NULL, 23 | title VARCHAR(75) NOT NULL, 24 | metaTitle VARCHAR(100) NULL, 25 | summary TEXT NULL, 26 | type SMALLINT NOT NULL DEFAULT 0, 27 | published SMALLINT NOT NULL DEFAULT 0, 28 | createdAt TIMESTAMP(0) NOT NULL, 29 | updatedAt TIMESTAMP(0) NULL DEFAULT NULL, 30 | publishedAt TIMESTAMP(0) NULL DEFAULT NULL, 31 | startsAt TIMESTAMP(0) NULL DEFAULT NULL, 32 | endsAt TIMESTAMP(0) NULL DEFAULT NULL, 33 | content TEXT NULL DEFAULT NULL, 34 | PRIMARY KEY (id), 35 | CONSTRAINT fk_poll_host 36 | FOREIGN KEY (surveyHostId) 37 | REFERENCES users (id) 38 | ON DELETE NO ACTION 39 | ON UPDATE NO ACTION); 40 | 41 | CREATE SEQUENCE poll_meta_seq; 42 | 43 | CREATE TABLE poll_meta ( 44 | id BIGINT NOT NULL DEFAULT NEXTVAL ('poll_meta_seq'), 45 | pollId BIGINT NOT NULL, 46 | key VARCHAR(50) NOT NULL, 47 | content TEXT NULL DEFAULT NULL, 48 | PRIMARY KEY (id) 49 | , 50 | CONSTRAINT uq_poll_meta UNIQUE (pollId, key), 51 | CONSTRAINT fk_meta_poll 52 | FOREIGN KEY (pollId) 53 | REFERENCES poll (id) 54 | ON DELETE NO ACTION 55 | ON UPDATE NO ACTION); 56 | 57 | CREATE INDEX idx_meta_poll ON poll_meta (pollId ASC); 58 | 59 | 60 | CREATE SEQUENCE poll_question_seq; 61 | 62 | CREATE TABLE poll_question ( 63 | id BIGINT NOT NULL DEFAULT NEXTVAL ('poll_question_seq'), 64 | pollId BIGINT NOT NULL, 65 | type VARCHAR(50) NOT NULL, 66 | active SMALLINT NOT NULL DEFAULT 0, 67 | createdAt TIMESTAMP(0) NOT NULL, 68 | updatedAt TIMESTAMP(0) NULL DEFAULT NULL, 69 | content TEXT NULL DEFAULT NULL, 70 | PRIMARY KEY (id) 71 | , 72 | CONSTRAINT fk_question_poll 73 | FOREIGN KEY (pollId) 74 | REFERENCES poll (id) 75 | ON DELETE NO ACTION 76 | ON UPDATE NO ACTION); 77 | 78 | CREATE INDEX idx_question_poll ON poll_question (pollId ASC); 79 | 80 | CREATE SEQUENCE poll_answer_seq; 81 | 82 | CREATE TABLE poll_answer ( 83 | id BIGINT NOT NULL DEFAULT NEXTVAL ('poll_answer_seq'), 84 | pollId BIGINT NOT NULL, 85 | questionId BIGINT NOT NULL, 86 | active SMALLINT NOT NULL DEFAULT 0, 87 | createdAt TIMESTAMP(0) NOT NULL, 88 | updatedAt TIMESTAMP(0) NULL DEFAULT NULL, 89 | content TEXT NULL DEFAULT NULL, 90 | PRIMARY KEY (id) , 91 | CONSTRAINT fk_answer_poll 92 | FOREIGN KEY (pollId) 93 | REFERENCES poll (id) 94 | ON DELETE NO ACTION 95 | ON UPDATE NO ACTION, 96 | CONSTRAINT fk_answer_question 97 | FOREIGN KEY (questionId) 98 | REFERENCES poll_question (id) 99 | ON DELETE NO ACTION 100 | ON UPDATE NO ACTION); 101 | 102 | CREATE INDEX idx_answer_poll ON poll_answer (pollId ASC); 103 | CREATE INDEX idx_answer_question ON poll_answer (questionId ASC); 104 | -------------------------------------------------------------------------------- /polls-database-schema/readme.md: -------------------------------------------------------------------------------- 1 | # Polls database Schema 2 | 3 | With this schema you can now start building an application in any languages of your choice to create a simple polls applications. 4 | 5 | ## Tables in this schema 6 | 7 | ### User Table 8 | In this section, we will design the User Table to store user information of the poll/survey owner. The same table can be used to relate the poll/survey owners so that the users can manage their own poll or survey and to track the voting activities. Below mentioned is the description of all the columns of the User Table. 9 | 10 | |Column name| Description| 11 | | ----------- | ----------- | 12 | |Id|The unique id to identify the user.| 13 | |First Name|The first name of the user.| 14 | |Last Name The last name of the user. 15 | |Email| The email of the user. It can be used for login and registration purposes.| 16 | |Password Hash| The password hash generated by the appropriate algorithm. We must avoid storing plain passwords.| 17 | |Host |The flag to identify whether user can host poll or survey.| 18 | |Registered At| This column can be used to calculate the life of the user with the application.| 19 | |Last Login | It can be used to identify the last login of the user.| 20 | |Intro |The brief introduction of the User to be displayed on the Poll or Survey Page.| 21 | |displayName| The owner details to be displayed on the Poll or Survey Page. | 22 | 23 | ### Poll Table 24 | In this section, we will design the Poll Table to store the poll and survey data. Below mentioned is the description of all the columns of the Poll Table. 25 | 26 | |Column name| Description| 27 | | ----------- | ----------- | 28 | |Id| The unique id to identify the poll/survey.| 29 | |Host Id| The host id to identify the poll/survey host.| 30 | |Title| The poll/survey title to be displayed on the Poll/Survey Page and the lists.| 31 | |Meta Title | The meta title to be used for browser title and SEO.| 32 | |Summary |The summary to mention the key highlights.| 33 | |Type |The type to distinguish between the poll and the survey.| 34 | |Published | It can be used to identify whether the poll/survey is publicly available.| 35 | |CreatedAt | It stores the date and time at which the poll/survey is created.| 36 | |UpdatedAt | It stores the date and time at which the poll/survey is updated.| 37 | |PublishedAt | It stores the date and time at which the poll/survey is published.| 38 | |StartsAt | It stores the date and time at which the poll/survey starts and open up for voting.| 39 | |EndsAt| It stores the date and time at which the poll/survey closes for voting.| 40 | |Content | The column used to store the poll/survey data.| 41 | 42 | 43 | ## Poll Metadata 44 | The Poll Metadata Table can be used to store additional information of a poll or survey including the poll banner URL etc. Below mentioned is the description of all the columns of the Poll Meta Table. 45 | 46 | |Column name| Description| 47 | | ----------- | ----------- | 48 | |Id |The unique id to identify the poll meta.| 49 | |PollId| The poll id to identify the parent poll/survey. | 50 | |Key| The key identifying the meta. | 51 | |Content| The column used to store the poll metadata. | 52 | 53 | ### Poll Question Table 54 | The Poll Question Table can be used to store the questions related to polls and surveys. The ideal scenario is to have one question for polls and multiple questions for surveys. Below mentioned is the description of all the columns of the Poll Question Table. 55 | 56 | |Column name| Description| 57 | | ----------- | ----------- | 58 | |Id| The unique id to identify the poll question.| 59 | |PollId| The poll id to identify the parent poll/survey. | 60 | |Type| The type of question. The type can be a single choice(Yes/No), multiple-choice, select, or input. | 61 | |Active| Flag to identify whether the question is active. | 62 | |CreatedAt | It stores the date and time at which the question is created. | 63 | |UpdatedAt | It stores the date and time at which the question is updated. | 64 | |Content| The column used to store the question. | 65 | 66 | 67 | ### Poll Answer Table 68 | The Poll Answer Table can be used to store the answers of single-choice, multiple-choice and select type questions. In case of single-choice question, the answers can be Yes and No. Below mentioned is the description of all the columns of the Poll Answer Table. 69 | 70 | |Column name| Description| 71 | | ----------- | ----------- | 72 | |Id| The unique id to identify the poll answer.| 73 | |PollId| The poll id to identify the parent poll/survey.| 74 | |QuestionId| The question id to identify the parent question.| 75 | |Active| Flag to identify whether the answer is active. | 76 | |CreatedAt| It stores the date and time at which the answer is created. | 77 | |UpdatedAt | It stores the date and time at which the answer is updated. | 78 | |Content| The column used to store the answer.| 79 | 80 | 81 | ### Poll Vote Table 82 | The Poll Vote Table can be used to store the user choices and inputs. Below mentioned is the description of all the columns of the Poll Vote Table. 83 | 84 | |Column name | Description| 85 | | ----------- | ----------- | 86 | |Id | The unique id to identify the poll vote. | 87 | |PollId | The poll id to identify the poll/survey.| 88 | |QuestionId | The question id to identify the question.| 89 | |AnswerId | The answer id to identify the answer.| 90 | |UserId | The user id to identify the user.| 91 | |CreatedAt | It stores the date and time at which the answer is created.| 92 | |UpdatedAt | It stores the date and time at which the answer is updated.| 93 | |Content | The column used to store the user input.| 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /postgresql-adventureworks/AdventureWorksPG.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/postgresql-samples-databases/963247e830b98e96d7114712ee794730b5b0ee5a/postgresql-adventureworks/AdventureWorksPG.gz -------------------------------------------------------------------------------- /postgresql-adventureworks/Call-CreatePGFlexServer.ps1: -------------------------------------------------------------------------------- 1 |  2 | 3 | $PGParams = @{} 4 | $PGParams.RGName = "timchappgtest6" 5 | $PGParams.Location = "eastus" 6 | $PGParams.PGServerName = "timchapflexpgtest6" 7 | $PGParams.PGAdminUserName = "postgres" 8 | $PGParams.PGAdminPassword = "Password12345!!" 9 | $PGParams.PGSkuTier = "GeneralPurpose" 10 | $PGParams.PGSku = "Standard_D2s_v3" 11 | 12 | $PGFlexServer = create-AzPGFlexibleServer @PGParams -------------------------------------------------------------------------------- /postgresql-adventureworks/CreatePostgreSQLFlexibleServer.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Modules Az.PostgreSQL 2 | 3 | if(-not(Get-AzResourceProvider -ProviderNamespace Microsoft.DBforPostgreSQL)) 4 | { 5 | Register-AzResourceProvider -ProviderNamespace Microsoft.DBforPostgreSQL 6 | } 7 | 8 | function create-AzPGFlexibleServer 9 | { 10 | <# 11 | Written by: Tim Chapman, Microsoft 09/2021 12 | .SYNOPSIS 13 | Wrapper script to quickly create an Azure Database for PostgreSQL Flexible Server 14 | 15 | .DESCRIPTION 16 | Wrapper script to quickly create an Azure Database for PostgreSQL Flexible Server. 17 | Will create a Resource Group if it doesn't already exist. 18 | Will create a firewall rule for your current public IP address. 19 | 20 | .EXAMPLE 21 | $PGParams = @{} 22 | $PGParams.RGName = "timchappgtestrg" 23 | $PGParams.Location = "eastus" 24 | $PGParams.PGServerName = "timchapflexpgtest" 25 | $PGParams.PGAdminUserName = "timchapman" 26 | $PGParams.PGAdminPassword = "Password12345!!" 27 | $PGParams.PGSkuTier = "GeneralPurpose" 28 | $PGParams.PGSku= "Standard_D2s_v3" 29 | 30 | $PGFlexServer = create-AzPGFlexibleServer @PGParams 31 | 32 | .PARAMETER RGName 33 | The name of the resource group. Will be created if it does not exist in the current subscription. 34 | 35 | .PARAMETER Location 36 | Region to put the PostgreSQL Flexible Server. 37 | 38 | .PARAMETER PGServerName 39 | Name of the PostgreSQL Flexible Server 40 | 41 | .PARAMETER PGAdminUserName 42 | Administrator username for the server. Once set, it cannot be changed. 43 | 44 | .PARAMETER PGAdminPassword 45 | The password of the administrator. Minimum 8 characters and maximum 128 characters. Password must contain characters from three of the following categories: English uppercase letters, English lowercase letters, numbers, and non-alphanumeric characters. 46 | 47 | .PARAMETER PGSkuTier 48 | Compute tier of the server. Accepted values: Burstable, GeneralPurpose, Memory Optimized. Default: Burstable. 49 | 50 | .PARAMETER PGSku 51 | The name of the sku, typically, tier + family + cores, e.g. Standard_B1ms, Standard_D2ds_v4. 52 | 53 | .PARAMETER PGVersion 54 | Version of PostgreSQL to be used 55 | 56 | .PARAMETER PGStorageInMb 57 | Max storage allowed for a server. 58 | #> 59 | param( 60 | [Parameter(Mandatory = $true, Position=0)] 61 | [string] $RGName , 62 | [Parameter(Mandatory = $true, Position=1)] 63 | [string] $Location, 64 | [Parameter(Mandatory = $true, Position=2)] 65 | [string] $PGServerName , 66 | [Parameter(Mandatory = $true, Position=3)] 67 | [string] $PGAdminUserName, 68 | [Parameter(Mandatory = $true, Position=4)] 69 | [string] $PGAdminPassword, 70 | [Parameter(Position=5)] 71 | [ValidateSet("GeneralPurpose", "MemoryOptimized", "Burstable")] 72 | [string] $PGSkuTier = "GeneralPurpose", 73 | [Parameter(Position=6)] 74 | [string] $PGSku = "Standard_B1ms", 75 | [Parameter(Position=7)] 76 | [ValidateScript({$_ -ge 11 -and $_%1 -eq 0})] 77 | [int] $PGVersion = 12 , 78 | [Parameter(Position = 8)] 79 | [ValidateSet("32768","65536","131072","262144","524288","1048576","2097152","4194304","8388608","16777216")] 80 | [int] $PGStorageInMb = 32768 81 | ) 82 | if(-not(Get-AzContext)) 83 | { 84 | Login-AzAccount 85 | } 86 | 87 | #servername must be lowercase or the deployment will fail. 88 | $PGServerName = $PGServerName.ToLower() 89 | 90 | $SkuMatch = $false 91 | 92 | if ($PGSkuTier -eq "Burstable" -and $PGSku -like "Standard_B*") 93 | { 94 | $SkuMatch = $true 95 | } 96 | elseif ($PGSkuTier -eq "GeneralPurpose" -and $PGSku -like "Standard_D*") 97 | { 98 | $SkuMatch = $true 99 | } 100 | elseif ($PGSkuTier -eq "MemoryOptimized" -and $PGSku -like "Standard_E*") 101 | { 102 | $SkuMatch = $true 103 | } 104 | else 105 | { 106 | Write-Error "SKU and SKU Tier mismatch" 107 | return 108 | } 109 | 110 | if(-not(Get-AzResourceGroup -Name $RGName -Location $Location -ErrorAction Ignore)) 111 | { 112 | $RG = New-AzResourceGroup -Name $RGName -Location $Location 113 | } 114 | 115 | [SecureString]$Password = ConvertTo-SecureString $PGAdminPassword -AsPlainText -Force 116 | $PostgreSQLParams = @{} 117 | $PostgreSQLParams.Name = $PGServerName 118 | $PostgreSQLParams.ResourceGroupName = $RGName 119 | $PostgreSQLParams.Location = $Location 120 | $PostgreSQLParams.AdministratorUsername = $PGAdminUserName 121 | $PostgreSQLParams.AdministratorLoginPassword = $Password 122 | $PostgreSQLParams.SkuTier = $PGSkuTier 123 | $PostgreSQLParams.Sku = $PGSku 124 | $PostgreSQLParams.Version = $PGVersion 125 | $PostgreSQLParams.StorageInMb = $PGStorageInMb 126 | $PostgreSQLParams.PublicAccess = "None" 127 | $PGServerObject = New-AzPostgreSqlFlexibleServer @PostgreSQLParams 128 | 129 | $MyIPAddress = Invoke-RestMethod http://ipinfo.io/json | select -exp ip 130 | $FirewallRuleName = "pgallowedips-$PGServerName" 131 | $FirewallRules = @{} 132 | $FirewallRules.ResourceGroupName = $RGName 133 | $FirewallRules.ServerName = $PGServerName 134 | $FirewallRules.FirewallRuleName = $FirewallRuleName 135 | $FirewallRules.StartIpAddress = $MyIPAddress 136 | $FirewallRules.EndIpAddress = $MyIPAddress 137 | 138 | $ServerFirewallRule = New-AzPostgreSqlFlexibleServerFirewallRule @FirewallRules 139 | 140 | return $PGServerObject 141 | } 142 | 143 | -------------------------------------------------------------------------------- /postgresql-adventureworks/README.md: -------------------------------------------------------------------------------- 1 | # AdventureWorks database for Azure Database for PostgreSQL Flexible Server 2 | This project restores the SQL Server AdventureWorks 2016 database backup converted to PostgreSQL schema to an Azure Database for PostgreSQL Flexible Server instance. 3 | ## 1. Provision an Azure Database for PostgreSQL Flexible Server instance 4 | 1. Open the script CreatePostgreSQLFlexibleServer.ps1 in Visual Studio Code or PowerShell ISE. 5 | 2. Alter the parameters for the function to match what you want the servername, resource group, region and server parameters to be. 6 | ![Server Parameters.](media/1a-RunFunction.JPG 'Server Parameters') 7 | 3. The script call will output a Server object which we can use to get the Fully Qualified Name of the server. We will use this server name to connect to the PostgreSQL database via psql. 8 | The output will look similar to this: 9 | ![Fully Qualified Server Name.](media/1b-ServerName.JPG 'Server Name') 10 | 11 | You can also grab the above function call [here.](./Call-CreatePGFlexServer.ps1) 12 | 13 | **I highly recommend to create the server using the postgres user as the admin user account. The AdventureWorks backup was created with the postgres user owning all objects and will error if the restore occurs under a different account.** 14 | 15 | ## 2. Enable the necessary PostgreSQL extensions 16 | 1. Navigate to the 'Server Parameters' section for the Azure Database for PostgreSQL Flexible Server. 17 | 2. Find the azure.extensions option from the Server parameters list and enable the 'TABLEFUNC' and 'UUID-OSSP' extensions. The AdventureWorks database uses these features and the database restore will error if these extensions are not enabled. 18 | 3. Click the Save option to enable these extensions on the server. 19 | ![Create Extensions.](media/1c-Extensions.jpg 'PostgreSQL Extensions') 20 | 21 | ## 3. Create the AdventureWorks database on the Azure Database for PostgreSQL Flexible Server 22 | 1. Download and install PGAdmin: https://www.pgadmin.org/download/ 23 | 2. Navigate to where PGAdmin is installed (the location of D:\Program Files\pgAdmin 4\v5\runtime on this test machine) and open a Command Prompt. 24 | 3. Execute the following command to connect to the PostgreSQL Flexible Server. Be sure to use the Fully Qualified Name of your server and to enter your Password when prompted. 25 | ``` 26 | psql.exe "host=timchapflexpgtest6.postgres.database.azure.com port=5432 dbname=postgres user=postgres" 27 | ``` 28 | The output will look similar to the following: 29 | ![Server Login.](media/2a-PSQLLogin.JPG 'PSQL Login') 30 | 4. Create the AdventureWorks database by using the following SQL statement: 31 | ``` 32 | CREATE DATABASE adventureworks; 33 | ``` 34 | Which will have output similar to the following: 35 | ![Create Database.](media/2b-CreateDatabase.JPG 'Create Database') 36 | 37 | ## 4. Restore the AdventureWorks database on the Azure Database for PostgreSQL Flexible Server 38 | 1. Execute the pg_restore below. Be sure to use the Fully Qualified Name of your server and the location of where you've cloned this repo. 39 | ``` 40 | pg_restore -h timchapflexpgtest6.postgres.database.azure.com -U postgres -d adventureworks D:/GitHub/postgresql-adventureworks/AdventureWorksPG.gz 41 | ``` 42 | The output should look similar to the following. **Note: This script returns 2 Azure extension related errors. These can be safely ignored.** 43 | ![Restore Database.](media/3a-RestoreDatabase.JPG 'Restore Database') 44 | 45 | ## 5. Log into the AdventureWorks database via pgAdmin 46 | 1. Open pgAdmin. You may need to set up a password if this is your first time using it. 47 | 2. Under Browser, right click and choose Create-->Server Group. Give the Server Group a name and then Choose Save. Mine is named Flexible. 48 | 3. Enter the name of the Azure Database for PostgreSQL Flexible Server along with the username you chose when you created the Server. The output will look similar to the following: 49 | ![Register Server](media/4a-RegisterServer.JPG 'Register Server') 50 | 4. Expand the database in the Browser to view the AdventureWorks tables. 51 | ![Expand AW](media/4b-AWExpanded.JPG 'Expand AW') -------------------------------------------------------------------------------- /postgresql-adventureworks/media/1a-RunFunction.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/postgresql-samples-databases/963247e830b98e96d7114712ee794730b5b0ee5a/postgresql-adventureworks/media/1a-RunFunction.JPG -------------------------------------------------------------------------------- /postgresql-adventureworks/media/1b-ServerName.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/postgresql-samples-databases/963247e830b98e96d7114712ee794730b5b0ee5a/postgresql-adventureworks/media/1b-ServerName.JPG -------------------------------------------------------------------------------- /postgresql-adventureworks/media/1c-Extensions.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/postgresql-samples-databases/963247e830b98e96d7114712ee794730b5b0ee5a/postgresql-adventureworks/media/1c-Extensions.JPG -------------------------------------------------------------------------------- /postgresql-adventureworks/media/2a-PSQLLogin.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/postgresql-samples-databases/963247e830b98e96d7114712ee794730b5b0ee5a/postgresql-adventureworks/media/2a-PSQLLogin.JPG -------------------------------------------------------------------------------- /postgresql-adventureworks/media/2b-CreateDatabase.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/postgresql-samples-databases/963247e830b98e96d7114712ee794730b5b0ee5a/postgresql-adventureworks/media/2b-CreateDatabase.JPG -------------------------------------------------------------------------------- /postgresql-adventureworks/media/3a-RestoreDatabase.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/postgresql-samples-databases/963247e830b98e96d7114712ee794730b5b0ee5a/postgresql-adventureworks/media/3a-RestoreDatabase.JPG -------------------------------------------------------------------------------- /postgresql-adventureworks/media/4a-RegisterServer.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/postgresql-samples-databases/963247e830b98e96d7114712ee794730b5b0ee5a/postgresql-adventureworks/media/4a-RegisterServer.JPG -------------------------------------------------------------------------------- /postgresql-adventureworks/media/4b-AWExpanded.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/postgresql-samples-databases/963247e830b98e96d7114712ee794730b5b0ee5a/postgresql-adventureworks/media/4b-AWExpanded.JPG --------------------------------------------------------------------------------